Sha256: 387ce5cca2d75f870f313188da65f0485a3be1da3ebc0d88e88575389c977ff3

Contents?: true

Size: 459 Bytes

Versions: 8

Compression:

Stored size: 459 Bytes

Contents

class Hash
  # Stolen from ActiveSupport
  def transform_keys
    return enum_for(:transform_keys) { size } unless block_given?
    result = {}
    each_key do |key|
      result[yield(key)] = self[key]
    end
    result
  end

  # Returns a new hash with all keys converted to strings.
  #
  #   hash = { name: 'Rob', age: '28' }
  #
  #   hash.stringify_keys
  #   # => {"name"=>"Rob", "age"=>"28"}
  def stringify_keys
    transform_keys(&:to_s)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
json_logic-0.4.7 lib/core_ext/stringify_keys.rb
json_logic-0.4.6 lib/core_ext/stringify_keys.rb
json_logic-0.4.5 lib/core_ext/stringify_keys.rb
json_logic-0.4.4 lib/core_ext/stringify_keys.rb
json_logic-0.4.3 lib/core_ext/stringify_keys.rb
json_logic-0.4.1 lib/core_ext/stringify_keys.rb
json_logic-0.4.0 lib/core_ext/stringify_keys.rb
json_logic-0.3 lib/core_ext/stringify_keys.rb