Skip to content

Instantly share code, notes, and snippets.

@rickbacci
Created September 14, 2015 21:13
Show Gist options
  • Select an option

  • Save rickbacci/3d29aff4fba0ca445c0e to your computer and use it in GitHub Desktop.

Select an option

Save rickbacci/3d29aff4fba0ca445c0e to your computer and use it in GitHub Desktop.
get in
data = { an_outer: "hash",
with_another: {
inner: "hash",
and_another: {
inside: "that"
}
}
}
keys = [:with_another, :and_another, :inside]
def get_in(data, keys)
key = keys.shift
new_data = data[key]
if keys.size > 0
get_in(new_data, keys)
else
return data[key]
end
end
p get_in(data, keys)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment