Class: HashWithIndifferentAccess
- Inherits:
-
Object
- Object
- HashWithIndifferentAccess
- Defined in:
- lib/hash_with_indifferent_access.rb
Instance Method Summary collapse
-
#deep_find(path, default = nil) ⇒ Object
Perform a depth first search of this hash and return the first element matching
path
, ordefault
if nothing found.
Instance Method Details
#deep_find(path, default = nil) ⇒ Object
Perform a depth first search of this hash and return the first element matching path
, or default
if nothing found.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/hash_with_indifferent_access.rb', line 11 def deep_find(path, default = nil) return default unless path path = [path] if path.is_a?(String) || path.is_a?(Symbol) return default unless path.is_a?(Array) && !path.empty? location = self path.each do |key| return default if location.nil? || !location.key?(key) location = location[key] end return location end |