[前][次][番号順一覧][スレッド一覧]

ruby-changes:31503

From: glass <ko1@a...>
Date: Fri, 8 Nov 2013 18:42:01 +0900 (JST)
Subject: [ruby-changes:31503] glass:r43582 (trunk): * lib/open3.rb: receive arguments as keyword arguments.

glass	2013-11-08 18:41:55 +0900 (Fri, 08 Nov 2013)

  New Revision: 43582

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43582

  Log:
    * lib/open3.rb: receive arguments as keyword arguments.

  Modified files:
    trunk/ChangeLog
    trunk/lib/open3.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43581)
+++ ChangeLog	(revision 43582)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Nov  8 18:35:31 2013  Masaki Matsushita  <glass.saga@g...>
+
+	* lib/open3.rb: receive arguments as keyword arguments.
+
 Fri Nov  8 13:19:26 2013  Masaki Matsushita  <glass.saga@g...>
 
 	* io.c (rb_io_open_with_args): use RARRAY_CONST_PTR().
Index: lib/open3.rb
===================================================================
--- lib/open3.rb	(revision 43581)
+++ lib/open3.rb	(revision 43582)
@@ -79,13 +79,7 @@ module Open3 https://github.com/ruby/ruby/blob/trunk/lib/open3.rb#L79
   # If merged stdout and stderr output is not a problem, you can use Open3.popen2e.
   # If you really need stdout and stderr output as separate strings, you can consider Open3.capture3.
   #
-  def popen3(*cmd, &block)
-    if Hash === cmd.last
-      opts = cmd.pop.dup
-    else
-      opts = {}
-    end
-
+  def popen3(*cmd, **opts, &block)
     in_r, in_w = IO.pipe
     opts[:in] = in_r
     in_w.sync = true
@@ -140,13 +134,7 @@ module Open3 https://github.com/ruby/ruby/blob/trunk/lib/open3.rb#L134
   #     p o.read #=> "*"
   #   }
   #
-  def popen2(*cmd, &block)
-    if Hash === cmd.last
-      opts = cmd.pop.dup
-    else
-      opts = {}
-    end
-
+  def popen2(*cmd, **opts, &block)
     in_r, in_w = IO.pipe
     opts[:in] = in_r
     in_w.sync = true
@@ -189,13 +177,7 @@ module Open3 https://github.com/ruby/ruby/blob/trunk/lib/open3.rb#L177
   #     }
   #   }
   #
-  def popen2e(*cmd, &block)
-    if Hash === cmd.last
-      opts = cmd.pop.dup
-    else
-      opts = {}
-    end
-
+  def popen2e(*cmd, **opts, &block)
     in_r, in_w = IO.pipe
     opts[:in] = in_r
     in_w.sync = true
@@ -266,16 +248,7 @@ module Open3 https://github.com/ruby/ruby/blob/trunk/lib/open3.rb#L248
   #     STDOUT.binmode; print thumnail
   #   end
   #
-  def capture3(*cmd)
-    if Hash === cmd.last
-      opts = cmd.pop.dup
-    else
-      opts = {}
-    end
-
-    stdin_data = opts.delete(:stdin_data) || ''
-    binmode = opts.delete(:binmode)
-
+  def capture3(*cmd, stdin_data: '', binmode: false, **opts)
     popen3(*cmd, opts) {|i, o, e, t|
       if binmode
         i.binmode
@@ -320,16 +293,7 @@ module Open3 https://github.com/ruby/ruby/blob/trunk/lib/open3.rb#L293
   #   End
   #   image, s = Open3.capture2("gnuplot", :stdin_data=>gnuplot_commands, :binmode=>true)
   #
-  def capture2(*cmd)
-    if Hash === cmd.last
-      opts = cmd.pop.dup
-    else
-      opts = {}
-    end
-
-    stdin_data = opts.delete(:stdin_data) || ''
-    binmode = opts.delete(:binmode)
-
+  def capture2(*cmd, stdin_data: '', binmode: false, **opts)
     popen2(*cmd, opts) {|i, o, t|
       if binmode
         i.binmode
@@ -359,16 +323,7 @@ module Open3 https://github.com/ruby/ruby/blob/trunk/lib/open3.rb#L323
   #   # capture make log
   #   make_log, s = Open3.capture2e("make")
   #
-  def capture2e(*cmd)
-    if Hash === cmd.last
-      opts = cmd.pop.dup
-    else
-      opts = {}
-    end
-
-    stdin_data = opts.delete(:stdin_data) || ''
-    binmode = opts.delete(:binmode)
-
+  def capture2e(*cmd, stdin_data: '', binmode: false, **opts)
     popen2e(*cmd, opts) {|i, oe, t|
       if binmode
         i.binmode
@@ -424,13 +379,7 @@ module Open3 https://github.com/ruby/ruby/blob/trunk/lib/open3.rb#L379
   #     stdin.close     # send EOF to sort.
   #     p stdout.read   #=> "     1\tbar\n     2\tbaz\n     3\tfoo\n"
   #   }
-  def pipeline_rw(*cmds, &block)
-    if Hash === cmds.last
-      opts = cmds.pop.dup
-    else
-      opts = {}
-    end
-
+  def pipeline_rw(*cmds, **opts, &block)
     in_r, in_w = IO.pipe
     opts[:in] = in_r
     in_w.sync = true
@@ -480,13 +429,7 @@ module Open3 https://github.com/ruby/ruby/blob/trunk/lib/open3.rb#L429
   #     p ts[1].value #=> #<Process::Status: pid 24913 exit 0>
   #   }
   #
-  def pipeline_r(*cmds, &block)
-    if Hash === cmds.last
-      opts = cmds.pop.dup
-    else
-      opts = {}
-    end
-
+  def pipeline_r(*cmds, **opts, &block)
     out_r, out_w = IO.pipe
     opts[:out] = out_w
 
@@ -522,13 +465,7 @@ module Open3 https://github.com/ruby/ruby/blob/trunk/lib/open3.rb#L465
   #     i.puts "hello"
   #   }
   #
-  def pipeline_w(*cmds, &block)
-    if Hash === cmds.last
-      opts = cmds.pop.dup
-    else
-      opts = {}
-    end
-
+  def pipeline_w(*cmds, **opts, &block)
     in_r, in_w = IO.pipe
     opts[:in] = in_r
     in_w.sync = true
@@ -581,13 +518,7 @@ module Open3 https://github.com/ruby/ruby/blob/trunk/lib/open3.rb#L518
   #     p err_r.read # error messages of pdftops and lpr.
   #   }
   #
-  def pipeline_start(*cmds, &block)
-    if Hash === cmds.last
-      opts = cmds.pop.dup
-    else
-      opts = {}
-    end
-
+  def pipeline_start(*cmds, **opts, &block)
     if block
       pipeline_run(cmds, opts, [], [], &block)
     else
@@ -649,13 +580,7 @@ module Open3 https://github.com/ruby/ruby/blob/trunk/lib/open3.rb#L580
   #   #   106
   #   #   202
   #
-  def pipeline(*cmds)
-    if Hash === cmds.last
-      opts = cmds.pop.dup
-    else
-      opts = {}
-    end
-
+  def pipeline(*cmds, **opts)
     pipeline_run(cmds, opts, [], []) {|ts|
       ts.map {|t| t.value }
     }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]