2011-11-14 57 views

回答

2

喜歡的東西:

def follow_hash(hash, path) 
    path.inject(hash) { |accum, el| accum && accum[el] } 
end 

value = follow_hash(hash, [:foo, :bar, :baz]) 
puts value if value 
+0

我喜歡這樣。填充。 –