Sha256: e9860d421aa7330354b5b4377c29f81aa325797b3e85cea55fb655baae45eb9f
Contents?: true
Size: 751 Bytes
Versions: 1
Compression:
Stored size: 751 Bytes
Contents
# encoding: utf-8 class Hash # Convert hash to command line options # # @example Convert true value # # hash = { # opt1: true # } # # hash.to_options # # => [ '--opt1'] # # @example Convert false value # # hash = { # opt1: false # } # # hash.to_options # # => [ '--no-opt1'] # # @example Convert other values # # hash = { # opt1: 'string' # } # # hash.to_options # # => [ '--opt1', 'string'] def to_options each_with_object([]) do |(key, value), a| if value.is_a? TrueClass a << "--#{key}" elsif value.is_a? FalseClass a << "--no-#{key}" else a << "--#{key}" a << value.to_s end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
fedux_org-stdlib-0.6.40 | lib/fedux_org_stdlib/core_ext/hash/options.rb |