Module: Meteoservice::NestedHashValue

Included in:
TownsData
Defined in:
lib/meteoservice/nested_hash_value.rb

Instance Method Summary collapse

Instance Method Details

#nested_hash_value(obj, key) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/meteoservice/nested_hash_value.rb', line 5

def nested_hash_value(obj, key)
  if obj.respond_to?(:key?) && obj.key?(key)
    obj[key]
  elsif obj.respond_to?(:each)
    r = nil

    obj.find { |*a| r = nested_hash_value(a.last, key) }
    r
  end
end