Sha256: 8b7e1f217d57504830a2f018f606da21e21f93106673e6352191d4e00ad2df8a

Contents?: true

Size: 582 Bytes

Versions: 1

Compression:

Stored size: 582 Bytes

Contents

class Hash
  # Defines deep_transform_keys as available in ActiveSupport >= 4.0.2.
  # See {http://apidock.com/rails/v4.2.1/Hash/deep_transform_keys}
  def deep_transform_keys(&block)
    deep_transform_in_object(self, &block)
  end

  private 

  def deep_transform_in_object(obj, &block)
    case obj 
      when Hash
        obj.each_with_object({}) do |(key,value), result|
          result[yield(key)] = deep_transform_in_object(value, &block)
        end
      when Array
        obj.map { |el| deep_transform_in_object(el, &block) }
      else
        obj
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cp-sparrow-0.0.14 lib/sparrow/core_ext/hash.rb