Method: Weak::Map::WeakKeysWithDelete#fetch
- Defined in:
- lib/weak/map/weak_keys_with_delete.rb
#fetch(key, default = UNDEFINED) {|key| ... } ⇒ Object
Note:
Set does not test member equality with ==
or eql?
.
Instead, it always checks strict object equality, so that, e.g.,
different strings are not considered equal, even if they may contain
the same string content.
Returns a value from the hash for the given key
. If the key can't be
found, there are several options: With no other arguments, it will raise
a KeyError
exception; if default
is given, then that value will be
returned; if the optional code block is specified, then it will be
called and its result returned.
94 95 96 97 98 |
# File 'lib/weak/map/weak_keys_with_delete.rb', line 94 def fetch(key, default = UNDEFINED, &block) value = @map[key] value = _fetch_default(key, default, &block) if value.nil? && !@map.key?(key) value end |