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