Module: Gemmy::Patches::HashPatch::InstanceMethods::RecursiveKeys

Defined in:
lib/gemmy/patches/hash_patch.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.recursive_keys(hash) ⇒ Object



94
95
96
97
98
99
100
101
102
103
# File 'lib/gemmy/patches/hash_patch.rb', line 94

def self.recursive_keys hash
  toplevel_keys = hash.keys.map &Array.method(:wrap)
  toplevel_keys.map do |key_array|
    if hash[key].is_a? Hash
      key_array.concat recursive_keys hash[key]
    else
      key_array
    end
  end
end

Instance Method Details

#recursive_keysObject

returns an array of arrays. Each sub-array is a list of keys. This list can be passed to Hash#dig with a splat operator.



91
92
93
# File 'lib/gemmy/patches/hash_patch.rb', line 91

def recursive_keys
  Gemmy.patch("hash/i/recursive_keys").recursive_keys self
end