Class: IO::Pipe::Command
Overview
Wrapper of command and options.
Instance Method Summary collapse
-
#each(*args, **kwds, &block) ⇒ Object
Iterates command outputs.
-
#initialize(command:, each_args: nil, each_kwds: nil, open_args: {}) ⇒ Command
constructor
Creates instance.
-
#open(&block) ⇒ Object
Starts the command with
open_args
. -
#redirect(**to) ⇒ Object
Redirects outputs.
Constructor Details
#initialize(command:, each_args: nil, each_kwds: nil, open_args: {}) ⇒ Command
Creates instance.
40 41 42 |
# File 'lib/io/pipe.rb', line 40 def initialize(command:, each_args: nil, each_kwds: nil, open_args: {}) super end |
Instance Method Details
#each(*args, **kwds, &block) ⇒ Object
Iterates command outputs.
59 60 61 62 63 64 65 |
# File 'lib/io/pipe.rb', line 59 def each(*args, **kwds, &block) if block_given? open {|f| f.each(*each_args, *args, **each_kwds, **kwds, &block)} else with(each_args: args, each_kwds: kwds) end end |
#open(&block) ⇒ Object
Starts the command with open_args
.
45 46 47 |
# File 'lib/io/pipe.rb', line 45 def open(&block) IO.popen(command, **open_args, &block) end |
#redirect(**to) ⇒ Object
Redirects outputs.
76 77 78 79 |
# File 'lib/io/pipe.rb', line 76 def redirect(**to) open_args.update(to) self end |