Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Ruby

Idiom #329 Read value in a map

Assign to v the value stored in the map m for the key k.

Explain what happens if there is no entry for k in m.

v = m[k]

When the key k is not found, v will be determined by the hashes default proc (if any) or its default value nil.
var v = m[k];

If no entry, throw an exception; use TryGetValue or GetValueOrDefault instead.

New implementation...
< >
programming-idioms.org