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
zobbix-0.0.4 lib/zobbix/core_ext/hash.rb
zobbix-0.0.3 lib/zobbix/core_ext/hash.rb
zobbix-0.0.2 lib/zobbix/core_ext/hash.rb
zobbix-0.0.1 lib/zobbix/core_ext/hash.rb
powerpack-0.1.1 lib/powerpack/hash/symbolize_keys.rb
powerpack-0.1.0 lib/powerpack/hash/symbolize_keys.rb
powerpack-0.0.9 lib/powerpack/hash/symbolize_keys.rb
powerpack-0.0.8 lib/powerpack/hash/symbolize_keys.rb