Sha256: c54807a896305c26c36b39eb86cb51c45280eab75e323f7ad9ed9f02d356e798

Contents?: true

Size: 615 Bytes

Versions: 1

Compression:

Stored size: 615 Bytes

Contents

# frozen_string_literal: true

module CaseTransform2
  # @api private
  class HashExt
    def deep_transform_keys!(object, &block)
      _deep_transform_keys_in_object!(object, &block)
    end

    private

    def _deep_transform_keys_in_object!(object, &block)
      case object
      when Hash
        object.keys.each do |key|
          value = object.delete(key)
          object[yield(key)] = _deep_transform_keys_in_object!(value, &block)
        end
        object
      when Array
        object.map! { |e| _deep_transform_keys_in_object!(e, &block) }
      else
        object
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
case_transform2-1.0.0 lib/case_transform2/hash_ext.rb