Sha256: feda09a4dfdcc424e1ef501459407ee1ac64c440ca609483ab8d7645784ccdc1
Contents?: true
Size: 1.14 KB
Versions: 56
Compression:
Stored size: 1.14 KB
Contents
# encoding: utf-8 require 'shellwords' require 'fedux_org_stdlib/core_ext/shellwords/clean' # Hash 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'] # # @example Clean keys # # hash = { # '$opt1' => 'string' # } # # hash.to_options # # => [ '--opt1', 'string'] # # @example Escape values # # hash = { # 'opt1' => '$string' # } # # hash.to_options # # => [ '--opt1', '\$string'] def to_options each_with_object([]) do |(key, value), a| key = Shellwords.clean(key) if value.is_a? TrueClass a << "--#{key}" elsif value.is_a? FalseClass a << "--no-#{key}" else a << "--#{key}" a << Shellwords.escape(value) end end end end
Version data entries
56 entries across 56 versions & 1 rubygems