Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View get_path.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
class Hash
def deep(*path)
path.inject(self) {|h,k| h.respond_to?(:fetch) ? h.fetch(k, nil) : h}
end
end
 
#example
stuff = {
:foo => {
:bar => nil
},
:bar => {
:baz => :whatever,
:what => {:ever => nil }
}
}
 
p stuff.deep(:foo, :bar) || stuff.deep(:bar, :baz)
p stuff.deep(:foo, :bar) || stuff.deep(:bar, :baz) || stuff.deep(:bar, :what, :ever) || "nothing"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.