Created
August 27, 2014 15:25
-
-
Save rbxbx/032be2c1fc6efef67cd8 to your computer and use it in GitHub Desktop.
Similar to Clojure's get-in for Ruby hashes
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
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