From 53dc9794f0f2c726be249f8a4e22c1a778c336af Mon Sep 17 00:00:00 2001 From: glass Date: Fri, 8 Nov 2013 09:41:55 +0000 Subject: * lib/open3.rb: receive arguments as keyword arguments. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43582 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/open3.rb | 97 +++++++----------------------------------------------------- 1 file changed, 11 insertions(+), 86 deletions(-) (limited to 'lib/open3.rb') diff --git a/lib/open3.rb b/lib/open3.rb index 72fd6bb52f..134601c907 100644 --- a/lib/open3.rb +++ b/lib/open3.rb @@ -79,13 +79,7 @@ module Open3 # 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 # 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 # } # } # - 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 # 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 # 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 # # 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 # 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 # p ts[1].value #=> # # } # - 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 # 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 # 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 # # 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 } } -- cgit v1.2.3