Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/ratch/dsl/console.rb
Instance Method Summary collapse
-
#argumentize(args_field = nil) ⇒ Object
(also: #command_vector)
Turn a hash into arguments.
-
#to_console ⇒ Object
Convert an array into command line parameters.
Instance Method Details
#argumentize(args_field = nil) ⇒ Object Also known as: command_vector
Turn a hash into arguments.
h = { :list => [1,2], :base => "HI" }
h.argumentize #=> [ [], { :list => [1,2], :base => "HI" } ]
h.argumentize(:list) #=> [ [1,2], { :base => "HI" } ]
140 141 142 143 144 145 146 147 148 149 |
# File 'lib/ratch/dsl/console.rb', line 140 def argumentize(args_field=nil) config = dup if args_field args = [config.delete(args_field)].flatten.compact else args = [] end args << config return args end |
#to_console ⇒ Object
Convert an array into command line parameters. The array is accepted in the format of Ruby method arguments –ie. [arg1, arg2, …, hash]
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/ratch/dsl/console.rb', line 117 def to_console flags = collect do |f,v| m = f.to_s.size == 1 ? '-' : '--' case v when Array v.collect{ |e| "#{m}#{f}='#{e}'" }.join(' ') when true "#{m}#{f}" when false, nil '' else "#{m}#{f}='#{v}'" end end flags.join(" ") end |