Class: Rubsh::Command
- Inherits:
-
Object
- Object
- Rubsh::Command
- Defined in:
- lib/rubsh/command.rb
Overview
Represents an un-run system program, like "ls" or "cd". Because it represents the program itself (and not a running instance of it), it should hold very little state. In fact, the only state it does hold is baked options.
When a Command object is called, the result that is returned is a RunningCommand object, which represents the Command put into an execution state.
Instance Method Summary collapse
-
#bake(*args, **kwargs) ⇒ Command
A new instance of Command with baked options.
-
#call(*args, **kwargs) ⇒ RunningCommand
(also: #call_with)
An new instance of RunningCommand with execution state.
-
#initialize(sh, prog) ⇒ Command
constructor
A new instance of Command.
- #to_s ⇒ String
Constructor Details
#initialize(sh, prog) ⇒ Command
Returns a new instance of Command.
9 10 11 12 13 14 |
# File 'lib/rubsh/command.rb', line 9 def initialize(sh, prog) @sh = sh @prog = prog.to_s @progpath = resolve_progpath(@prog) @baked_opts = [] end |
Instance Method Details
#bake(*args, **kwargs) ⇒ Command
Returns a new instance of Command with baked options.
42 43 44 45 46 |
# File 'lib/rubsh/command.rb', line 42 def bake(*args, **kwargs) cmd = Command.new(@sh, @prog) cmd.__bake!(*@baked_opts, *args, **kwargs) cmd end |
#call(*args, **kwargs) ⇒ RunningCommand Also known as: call_with
Returns An new instance of RunningCommand with execution state.
32 33 34 35 36 |
# File 'lib/rubsh/command.rb', line 32 def call(*args, **kwargs) rcmd = RunningCommand.new(@sh, @prog, @progpath, *@baked_opts, *args, **kwargs) rcmd.__run rcmd end |
#to_s ⇒ String
49 50 51 |
# File 'lib/rubsh/command.rb', line 49 def to_s @progpath end |