diff --git a/lib/open4.rb b/lib/open4.rb index 0bac277..3229860 100644 --- a/lib/open4.rb +++ b/lib/open4.rb @@ -179,9 +179,9 @@ def run begin @argv.each do |a, b| - @threads << Thread.new(*a) do |*a| + @threads << Thread.new(*a) do |*th_a| begin - b[*a] + b[*th_a] ensure killall rescue nil if $! @done.push Thread.current @@ -210,9 +210,9 @@ def to timeout = nil def new_thread *a, &b cur = Thread.current - Thread.new(*a) do |*a| + Thread.new(*a) do |*th_a| begin - b[*a] + b[*th_a] rescue Exception => e cur.raise e end @@ -222,11 +222,11 @@ def new_thread *a, &b def getopts opts = {} lambda do |*args| - keys, default, ignored = args + keys, _, _ = args catch(:opt) do [keys].flatten.each do |key| - [key, key.to_s, key.to_s.intern].each do |key| - throw :opt, opts[key] if opts.has_key?(key) + [key, key.to_s, key.to_s.intern].each do |th_key| + throw :opt, opts[th_key] if opts.has_key?(th_key) end end default @@ -255,8 +255,8 @@ def relay src, dst = nil, t = nil q = Queue.new th = nil - timer_set = lambda do |t| - th = new_thread{ to(t){ q.pop } } + timer_set = lambda do |tt| + th = new_thread{ to(tt){ q.pop } } end timer_cancel = lambda do |t| @@ -265,9 +265,9 @@ def relay src, dst = nil, t = nil timer_set[t] begin - src.each do |buf| + src.each do |inner_buf| timer_cancel[t] - send_dst[buf] + send_dst[inner_buf] timer_set[t] end ensure @@ -338,17 +338,17 @@ def spawn arg, *argv te = ThreadEnsemble.new c - te.add_thread(i, stdin) do |i, stdin| - relay stdin, i, stdin_timeout - i.close rescue nil + te.add_thread(i, stdin) do |th_i, th_stdin| + relay stdin, th_i, stdin_timeout + th_i.close rescue nil end - te.add_thread(o, stdout) do |o, stdout| - relay o, stdout, stdout_timeout + te.add_thread(o, stdout) do |th_o, th_stdout| + relay th_o, th_stdout, stdout_timeout end - te.add_thread(e, stderr) do |o, stderr| - relay e, stderr, stderr_timeout + te.add_thread(e, stderr) do |th_o, th_stderr| + relay th_e, th_stderr, stderr_timeout end te.run @@ -382,7 +382,7 @@ def background arg, *argv else argv.push opts end - thread = Thread.new(arg, argv){|arg, argv| spawn arg, *argv} + thread = Thread.new(arg, argv){|th_arg, th_argv| spawn th_arg, *th_argv} sc = class << thread; self; end sc.module_eval { define_method(:pid){ @pid ||= q.pop }