summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOKURA Masafumi <masafumi.o1988@gmail.com>2026-04-06 18:34:36 +0900
committerGitHub <noreply@github.com>2026-04-06 18:34:36 +0900
commit9dab3c51fd5e18b18838e0da4ee20f313d25ba43 (patch)
treed04aecbc957cfa17eef801083cb81d3b2185ac61
parente0a7dad99d6f2e85528ca669ace9a9a3d171c843 (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.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/hash.c b/hash.c
index 773df7e78d..79dbd5d8e9 100644
--- a/hash.c
+++ b/hash.c
@@ -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].
*/