diff options
| author | OKURA Masafumi <masafumi.o1988@gmail.com> | 2026-04-06 18:34:36 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-04-06 18:34:36 +0900 |
| commit | 9dab3c51fd5e18b18838e0da4ee20f313d25ba43 (patch) | |
| tree | d04aecbc957cfa17eef801083cb81d3b2185ac61 | |
| parent | e0a7dad99d6f2e85528ca669ace9a9a3d171c843 (diff) | |
[DOC] Mention `Hash#default_proc=` affects Proc object from `Hash#to_proc`
```ruby
h = {foo: 0, bar: 1, baz: 2}
proc = h.to_proc
proc.call(:nosuch) # => nil
h.default_proc = proc {'wow!'} # This affects `proc` immediately
proc.call(:nosuch) # => 'wow!'
```
This behavior is a bit of surprise to me, and I could not find
any mention to this behavior in current doc.
| -rw-r--r-- | hash.c | 2 |
1 files changed, 2 insertions, 0 deletions
@@ -5012,6 +5012,8 @@ hash_proc_call(RB_BLOCK_CALL_FUNC_ARGLIST(key, hash)) * proc.call(:foo) # => 0 * proc.call(:bar) # => 1 * proc.call(:nosuch) # => nil + * h.default_proc = proc { |hash, key| "Missing key: #{key}" } # This affect the existing proc object + * proc.call(:nosuch) # => "Missing key: #{nosuch}" * * Related: see {Methods for Converting}[rdoc-ref:Hash@Methods+for+Converting]. */ |
