Skip to content

Instantly share code, notes, and snippets.

@akahn
Created August 12, 2013 18:44
Show Gist options
  • Select an option

  • Save akahn/6213768 to your computer and use it in GitHub Desktop.

Select an option

Save akahn/6213768 to your computer and use it in GitHub Desktop.
def find_value(key, hash)
result = hash
key.split('.').each do |segment|
segment = segment.to_i if segment =~ /\d+/
result = result[segment]
return unless result
end
result
end
# find_value('foo.0.bar, {'foo' => [{'bar' => 'hi!'}]})
# => 'hi!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment