Class: PolishGeeks::DevTools::Hash

Inherits:
Hash
  • Object
show all
Defined in:
lib/polish_geeks/dev_tools/hash.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#same_key_structure?(other) ⇒ Boolean

Returns true if both hashes have same keys and same keys structure.

Parameters:

  • other (Hash)

    different hash that we want to compare with

Returns:

  • (Boolean)

    true if both hashes have same keys and same keys structure



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/polish_geeks/dev_tools/hash.rb', line 10

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