Default Hash values are super easy in Ruby
Want a list?
list_default = Hash.new([])
That's pretty darn easy.
Edit: Thanks to @kaokun on twitter for catching this and correcting me. This will return the same array each time (having flashbacks to the first time I used mutable keyword args in python). To get a different array, you need need to pass a block with the behavior:
list_default = Hash.new { |hash, key| hash[key] = [] }
Just because your language hides pointers and references doesn't mean you can ignore them I guess.
Tweet