1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
glass 2013-11-08 09:41:55 +00:00
parent 05a4d176d6
commit 53dc9794f0
2 changed files with 15 additions and 86 deletions

View file

@ -1,3 +1,7 @@
Fri Nov 8 18:35:31 2013 Masaki Matsushita <glass.saga@gmail.com>
* lib/open3.rb: receive arguments as keyword arguments.
Fri Nov 8 13:19:26 2013 Masaki Matsushita <glass.saga@gmail.com>
* io.c (rb_io_open_with_args): use RARRAY_CONST_PTR().

View file

@ -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 #=> #<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
# 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 }
}