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-2.10.0 lib/hash_utils.rb
format_parser-2.9.0 lib/hash_utils.rb
format_parser-2.8.0 lib/hash_utils.rb
format_parser-2.7.2 lib/hash_utils.rb
format_parser-2.7.1 lib/hash_utils.rb
format_parser-2.7.0 lib/hash_utils.rb
format_parser-2.6.0 lib/hash_utils.rb
format_parser-2.5.0 lib/hash_utils.rb
format_parser-2.4.5 lib/hash_utils.rb
format_parser-2.4.4 lib/hash_utils.rb
format_parser-2.4.3 lib/hash_utils.rb
format_parser-2.3.0 lib/hash_utils.rb
format_parser-2.2.1 lib/hash_utils.rb
format_parser-2.2.0 lib/hash_utils.rb
format_parser-2.1.0 lib/hash_utils.rb
format_parser-2.0.0 lib/hash_utils.rb
format_parser-2.0.0.pre.4 lib/hash_utils.rb
format_parser-2.0.0.pre.3 lib/hash_utils.rb
format_parser-2.0.0.pre.2 lib/hash_utils.rb
format_parser-2.0.0.pre lib/hash_utils.rb