Created
October 24, 2014 03:00
-
-
Save chsh/c66c228e955f74789781 to your computer and use it in GitHub Desktop.
simple deep hash scanner
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
| # hash = { a: { b: 1 } } | |
| # path hash, :a, :b -> 1 | |
| def path(source, *keys) | |
| return nil unless source | |
| return nil unless source.respond_to? :[] | |
| keys.each do |key| | |
| return nil unless source.respond_to? :[] | |
| source = source[key] | |
| return nil unless source | |
| end | |
| source | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment