Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-unix-now.rb

Instance Method Summary collapse

Instance Method Details

#to_cmd_opt(style = :gnu) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/ruby-unix-now.rb', line 45

def to_cmd_opt(style = :gnu)
  map do |key, value|
    prefix = ((style == :gnu && key.to_s.size > 1) ? '--' : '-')
    assignment = (key.to_s.size == 1 || style == :unix) ? ' ' : '='
    value.is_a?(TrueClass) ? "#{prefix}#{key}" : "#{prefix}#{key}#{assignment}#{value}"
  end.join(' ')
end