End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Hash#default=
hash.default = value → object
hash.c
View on GitHub ↗
static VALUE
rb_hash_set_default(VALUE hash, VALUE ifnone)
{
rb_hash_modify_check(hash);
SET_DEFAULT(hash, ifnone);
return ifnone;
}
Sets the default value to value; returns value:
Example
h = {} h.default # => nil h.default = false # => false h.default # => false
See Default Values.
See also
#default
#default_proc
#deconstruct_keys
#default_proc=
also in
4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0