Skip to content

Instantly share code, notes, and snippets.

@rbxbx
Created August 27, 2014 15:25
Show Gist options
  • Save rbxbx/032be2c1fc6efef67cd8 to your computer and use it in GitHub Desktop.
Save rbxbx/032be2c1fc6efef67cd8 to your computer and use it in GitHub Desktop.
Similar to Clojure's get-in for Ruby hashes
def deep_fetch(*keys, &default)
keys.inject(self) do |hsh, key|
hsh.fetch(key, &(proc { |*args| return default.call(*args) } if default))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment