class Hash

Public Instance Methods

argumentize(args_field=nil) click to toggle source

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" } ]
# File lib/detroit/core_ext/to_console.rb, line 84
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
Also aliased as: command_vector
command_vector(args_field=nil)
Alias for: argumentize
to_argv() click to toggle source

Convert a Hash into command line parameters. The array is accepted in the format of Ruby method arguments –ie. [arg1, arg2, …, hash]

# File lib/detroit/core_ext/to_console.rb, line 60
def to_argv
  flags = []
  each do |f,v|
    m = f.to_s.size == 1 ? '-' : '--'
    case v
    when Array
      v.each{ |e| flags << "#{m}#{f}='#{e}'" }
    when true
      flags << "#{m}#{f}"
    when false, nil
      # nothing
    else
      flags << "#{m}#{f}='#{v}'"
    end
  end
  flags
end
to_console() click to toggle source

Convert a Hash into command line arguments. The array is accepted in the format of Ruby method arguments –ie. [arg1, arg2, …, hash]

# File lib/detroit/core_ext/to_console.rb, line 53
def to_console
  to_argv.join(' ')
end