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-0.25.2 lib/hash_utils.rb
format_parser-0.25.1 lib/hash_utils.rb
format_parser-0.25.0 lib/hash_utils.rb
format_parser-0.24.2 lib/hash_utils.rb
format_parser-0.24.1 lib/hash_utils.rb
format_parser-0.24.0 lib/hash_utils.rb
format_parser-0.23.1 lib/hash_utils.rb
format_parser-0.23.0 lib/hash_utils.rb
format_parser-0.22.1 lib/hash_utils.rb
format_parser-0.22.0 lib/hash_utils.rb