Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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.