When you use the block syntax with Hash.new to define a default value, you lock yourself to only using the square bracket syntax for value lookup. The fetch method ignores the block, default, and default_proc.

This bit me hard this week, and my pair, @gd, got to watch me flounder on why fetch wasn’t getting the default value.

By the way, the Hash.new with a block is great for memoization of calculated or network lookup data.

#Ruby #RubyTips #RubyGotchas #ThisWeekILearned #TWIL