Skip to content

Instantly share code, notes, and snippets.

@EdwardIII

EdwardIII/r.rb Secret

Created February 19, 2016 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EdwardIII/b09fd10ca441d224adce to your computer and use it in GitHub Desktop.
Save EdwardIII/b09fd10ca441d224adce to your computer and use it in GitHub Desktop.
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