Ruby’s Hash#default=

by john on July 21, 2011

If Ruby’s Hash#default= returned the Hash instead of the default object, you could write:

TRANSLATION = { 'hello' => 'bonjour' }.default=('unknown')
  • Eric

    “If only, if only,” the woodpecker sighs, “The bark on the tree was just a little bit softer.”

  • http://terriblelabs.com Jeremy Weiskotten

    How about something like this:

    TRANSLATION = { ‘hello’ => ‘bonjour’ }.with_default(‘unknown’)

    https://gist.github.com/1125319

Previous post:

Next post: