-
-
Save EdwardIII/b09fd10ca441d224adce to your computer and use it in GitHub Desktop.
This file contains 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
class Hash | |
def values_at_deep(key) | |
result = [] | |
result << self[key] | |
self.values.each do |hash_value| | |
values = [hash_value] unless hash_value.is_a? Array | |
values.each do |value| | |
result += value.find_all_values_for(key) if value.is_a? Hash | |
end | |
end | |
result.compact | |
end | |
end | |
params = { | |
:could_be_anything => { | |
:could_be_any_level => { | |
:server_message => "I want to get this value, which could be anything" | |
} | |
} | |
} | |
p params.values_at_deep(:server_message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment