Created
August 12, 2013 18:44
-
-
Save akahn/6213768 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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