Last active
June 4, 2019 21:50
-
-
Save Heavyblade/4362181389b207edb596abb367aba78b to your computer and use it in GitHub Desktop.
dig.rb
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 dig(row,array_of_keys) | |
| return row if array_of_keys.count == 0 | |
| current = case row | |
| when Hash | |
| current = row[array_of_keys.shift] | |
| when Array | |
| current = (row.find { |x| x.key?(key)} ||{})[key] | |
| else | |
| nil | |
| end | |
| dig(current, array_of_keys) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment