Sha256: de292c963d793e17f04c686871a5cdf80316628916c04071921155986d78ac8e

Contents?: true

Size: 641 Bytes

Versions: 50

Compression:

Stored size: 641 Bytes

Contents

# based on https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/hash/keys.rb#L116
# I chose to copy this method instead of adding activesupport as a dependency
# because we want to have the least number of dependencies
module FormatParser
  class HashUtils
    def self.deep_transform_keys(object, &block)
      case object
      when Hash
        object.each_with_object({}) do |(key, value), result|
          result[yield(key)] = deep_transform_keys(value, &block)
        end
      when Array
        object.map { |e| deep_transform_keys(e, &block) }
      else
        object
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
format_parser-1.7.0 lib/hash_utils.rb
format_parser-1.6.0 lib/hash_utils.rb
format_parser-1.5.0 lib/hash_utils.rb
format_parser-1.4.2 lib/hash_utils.rb
format_parser-1.4.1 lib/hash_utils.rb
format_parser-1.4.0 lib/hash_utils.rb
format_parser-1.3.0 lib/hash_utils.rb
format_parser-1.2.1 lib/hash_utils.rb
format_parser-1.2.0 lib/hash_utils.rb
format_parser-1.1.0 lib/hash_utils.rb
format_parser-1.0.0 lib/hash_utils.rb
format_parser-0.29.1 lib/hash_utils.rb
format_parser-0.29.0 lib/hash_utils.rb
format_parser-0.28.0 lib/hash_utils.rb
format_parser-0.27.0 lib/hash_utils.rb
format_parser-0.26.0 lib/hash_utils.rb
format_parser-0.25.6 lib/hash_utils.rb
format_parser-0.25.5 lib/hash_utils.rb
format_parser-0.25.4 lib/hash_utils.rb
format_parser-0.25.3 lib/hash_utils.rb