Class: Sh::Cmd
- Inherits:
-
Object
- Object
- Sh::Cmd
- Defined in:
- lib/sh.rb
Instance Method Summary collapse
- #arg(*args) ⇒ Object (also: #opt)
- #escape(str) ⇒ Object
- #exec ⇒ Object
-
#initialize(cmd = "") {|_self| ... } ⇒ Cmd
constructor
A new instance of Cmd.
- #to_s ⇒ Object
Constructor Details
#initialize(cmd = "") {|_self| ... } ⇒ Cmd
Returns a new instance of Cmd.
22 23 24 25 |
# File 'lib/sh.rb', line 22 def initialize(cmd="") @cmd, @args = cmd, [] yield self if block_given? end |
Instance Method Details
#arg(*args) ⇒ Object Also known as: opt
27 28 29 30 |
# File 'lib/sh.rb', line 27 def arg(*args) @args += args self end |
#escape(str) ⇒ Object
42 43 44 |
# File 'lib/sh.rb', line 42 def escape(str) Escape.shell_single_word(str).to_s end |
#exec ⇒ Object
37 38 39 |
# File 'lib/sh.rb', line 37 def exec `#{self.to_s}` end |
#to_s ⇒ Object
33 34 35 |
# File 'lib/sh.rb', line 33 def to_s [ @cmd ].concat(@args).map(&:to_s).map { |w| escape(w) }.join(' ') end |