Sha256: b11ec538db5b66739864bfd4648d091dba365c3d8d3448010cc3bde20ae44705

Contents?: true

Size: 905 Bytes

Versions: 7

Compression:

Stored size: 905 Bytes

Contents

# frozen_string_literal: true

module Anyway
  module Ext
    # Extend Hash through refinements
    module Hash
      refine ::Hash do
        # From ActiveSupport http://api.rubyonrails.org/classes/Hash.html#method-i-deep_merge
        def deep_merge!(other_hash)
          other_hash.each_pair do |current_key, other_value|
            this_value = self[current_key]

            if this_value.is_a?(::Hash) && other_value.is_a?(::Hash)
              this_value.deep_merge!(other_value)
              this_value
            else
              self[current_key] = other_value
            end
          end

          self
        end

        def stringify_keys!
          keys.each do |key|
            value = delete(key)
            value.stringify_keys! if value.is_a?(::Hash)
            self[key.to_s] = value
          end

          self
        end
      end

      using self
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
anyway_config-2.0.0.pre2 lib/anyway/ext/hash.rb
anyway_config-2.0.0.pre lib/anyway/ext/hash.rb
anyway_config-1.4.4 lib/anyway/ext/hash.rb
anyway_config-1.4.3 lib/anyway/ext/hash.rb
anyway_config-1.4.2 lib/anyway/ext/hash.rb
anyway_config-1.4.1 lib/anyway/ext/hash.rb
anyway_config-1.4.0 lib/anyway/ext/hash.rb