Sha256: 4d08d89ae16d8a1487214a284f0d4816e24c7dafd12d33ca58850908127bbb23

Contents?: true

Size: 847 Bytes

Versions: 11

Compression:

Stored size: 847 Bytes

Contents

module PolishGeeks
  module DevTools
    # Hash extensions required only by rake tasks in this rake file
    # No need to add them to app itself
    # We don't put it directly into hash, since it won't be used outside of
    # this gem
    class Hash < ::Hash
      # @param other [Hash] different hash that we want to compare with
      # @return [Boolean] true if both hashes have same keys and same keys structure
      def same_key_structure?(other)
        return false unless keys == other.keys &&
            keys.all? { |inside| inside.is_a?(Symbol) || inside.is_a?(String) }

        keys.all? do |inside|
          if self[inside].is_a?(::Hash)
            self.class.new.merge(self[inside]).same_key_structure?(other[inside])
          else
            !other[inside].is_a?(::Hash)
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
polishgeeks-dev-tools-1.4.0 lib/polish_geeks/dev_tools/hash.rb
polishgeeks-dev-tools-1.3.2 lib/polish_geeks/dev_tools/hash.rb
polishgeeks-dev-tools-1.3.1 lib/polish_geeks/dev_tools/hash.rb
polishgeeks-dev-tools-1.3.0 lib/polish_geeks/dev_tools/hash.rb
polishgeeks-dev-tools-1.2.1 lib/polishgeeks/dev-tools/hash.rb
polishgeeks-dev-tools-1.2.0 lib/polishgeeks/dev-tools/hash.rb
polishgeeks-dev-tools-1.1.3 lib/polishgeeks/dev-tools/hash.rb
polishgeeks-dev-tools-1.1.2 lib/polishgeeks/dev-tools/hash.rb
polishgeeks-dev-tools-1.1.1 lib/polishgeeks/dev-tools/hash.rb
polishgeeks-dev-tools-1.1.0 lib/polishgeeks/dev-tools/hash.rb
polishgeeks-dev-tools-1.0.0 lib/polishgeeks/dev-tools/hash.rb