Class: Sh::Cmd

Inherits:
Object
  • Object
show all
Defined in:
lib/sh.rb

Instance Method Summary collapse

Constructor Details

#initialize(cmd = "") {|_self| ... } ⇒ Cmd

Returns a new instance of Cmd.

Yields:

  • (_self)

Yield Parameters:

  • _self (Sh::Cmd)

    the object that the method was called on



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

#execObject



37
38
39
# File 'lib/sh.rb', line 37

def exec
  `#{self.to_s}`
end

#to_sObject



33
34
35
# File 'lib/sh.rb', line 33

def to_s
  [ @cmd ].concat(@args).map(&:to_s).map { |w| escape(w) }.join(' ')
end