Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Hash#default_proc=

hash.default_proc = proc → proc

Sets the default proc for self to proc: (see Default Values):

Example
h = {}
h.default_proc # => nil
h.default_proc = proc { |hash, key| "Default value for #{key}" }
h.default_proc.class # => Proc
h.default_proc = nil
h.default_proc # => nil
See also #default_proc #delete #default= #delete_if also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0