Sha256: 14230fe4d1d99aeb2bd1c64819da506193e02f310df92cac4560cbaf4f930fa3

Contents?: true

Size: 503 Bytes

Versions: 28

Compression:

Stored size: 503 Bytes

Contents

unless Hash.method_defined? :symbolize_keys
  class Hash
    # Converts the keys of the hash to symbols.
    #
    # @return [Hash] a copy of the original hash with its keys converted to symbols. Leave nonconvertible keys untouched when symbolizing keys.
    #
    # @example
    #   { 'one' => 1, 'two' => 2 }.symbolize_keys #=> { :one => 1, :two => 2 }
    #   { 1 => "a" }.symbolize_keys #=> { 1 => "a" }
    def symbolize_keys
      Hash[map { |(k, v)| [(k.to_sym rescue k), v] }]
    end
  end
end

Version data entries

28 entries across 25 versions & 7 rubygems

Version Path
powerpack-0.1.3 lib/powerpack/hash/symbolize_keys.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.2/lib/powerpack/hash/symbolize_keys.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.2/lib/powerpack/hash/symbolize_keys.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.2/lib/powerpack/hash/symbolize_keys.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.2/lib/powerpack/hash/symbolize_keys.rb
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.2/lib/powerpack/hash/symbolize_keys.rb
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.1/lib/powerpack/hash/symbolize_keys.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.1/lib/powerpack/hash/symbolize_keys.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/powerpack-0.1.2/lib/powerpack/hash/symbolize_keys.rb
powerpack-0.1.2 lib/powerpack/hash/symbolize_keys.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/lib/powerpack/hash/symbolize_keys.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/lib/powerpack/hash/symbolize_keys.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/lib/powerpack/hash/symbolize_keys.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/lib/powerpack/hash/symbolize_keys.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/lib/powerpack/hash/symbolize_keys.rb
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/powerpack-0.1.1/lib/powerpack/hash/symbolize_keys.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/powerpack-0.1.1/lib/powerpack/hash/symbolize_keys.rb
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/powerpack-0.0.9/lib/powerpack/hash/symbolize_keys.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/powerpack-0.0.9/lib/powerpack/hash/symbolize_keys.rb
zobbix-0.1.0 lib/zobbix/core_ext/hash.rb