Module: Hashie::Extensions::DeepFind

Defined in:
lib/hashie/extensions/deep_find.rb

Instance Method Summary collapse

Instance Method Details

#deep_find(key) ⇒ Object Also known as: deep_detect

Performs a depth-first search on deeply nested data structures for a key and returns the first occurrence of the key.

options = {location: {address: '123 Street'}} options.deep_find(:address) # => '123 Street'



9
10
11
# File 'lib/hashie/extensions/deep_find.rb', line 9

def deep_find(key)
  _deep_find(key)
end

#deep_find_all(key) ⇒ Object Also known as: deep_select

Performs a depth-first search on deeply nested data structures for a key and returns all occurrences of the key.

options = [{location: {address: '123 Street'}, {address: '234 Street'}]} options.deep_find_all(:address) # => ['123 Street', '234 Street']



20
21
22
23
# File 'lib/hashie/extensions/deep_find.rb', line 20

def deep_find_all(key)
  matches = _deep_find_all(key)
  matches.empty? ? nil : matches
end