If Ruby’s Hash#default= returned the Hash instead of the default object, you could write:
TRANSLATION = { 'hello' => 'bonjour' }.default=('unknown')
If Ruby’s Hash#default= returned the Hash instead of the default object, you could write:
TRANSLATION = { 'hello' => 'bonjour' }.default=('unknown')
Previous post: Use of the word “bind” in JavaScript libraries
Next post: Spying on Ruby’s Net::HTTP
{ 2 comments… read them below or add one }
“If only, if only,” the woodpecker sighs, “The bark on the tree was just a little bit softer.”
How about something like this:
TRANSLATION = { ‘hello’ => ‘bonjour’ }.with_default(’unknown’)
https://gist.github.com/1125319