From: "Earlopain (Earlopain _) via ruby-core" Date: 2026-08-16T13:50:49+00:00 Subject: [ruby-core:126404] [Ruby Misc#10513] instance_eval yields the receiver, but is documented to yield no arguments Issue #10513 has been updated by Earlopain (Earlopain _). Status changed from Assigned to Closed Current docs now specify this ---------------------------------------- Misc #10513: instance_eval yields the receiver, but is documented to yield no arguments https://bugs.ruby-lang.org/issues/10513#change-118542 * Author: ctm (Cliff Matthews) * Status: Closed * Assignee: zzak (zzak _) ---------------------------------------- instance_eval yields the receiver, but is documented as yielding no arguments. I searched the bug reports before writing this up and found bug #2476 which was closed with a message that contained "instance_eval yields the receiver in both 1.8 and 1.9. Unfortunately, a Proc object created by lambda raises ArgumentError when extra arguments are yielded in 1.9.". However such behavior is not expected when the calling sequence is: ~~~ * call-seq: * obj.instance_eval(string [, filename [, lineno]] ) -> obj * obj.instance_eval {| | block } -> obj ~~~ This discrepancy surprised me, but once I realized what was going on I simply used instance_exec instead of instance_eval. All else equal, I would prefer for instance_eval to to not yield the receiver since I can pick up the receiver as self if I want to, but such a change could breaking existing code, so probably documenting the current behavior is better. ~~~ bash-3.2$ ruby --version ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin14.0] bash-3.2$ ./instance_eval This is the lambda that *does* work. arg = 32 self = 32 ./instance_eval:6:in `block in
': wrong number of arguments (1 for 0) (ArgumentError) from ./instance_eval:17:in `instance_eval' from ./instance_eval:17:in `
' ~~~ ---Files-------------------------------- instance_eval (561 Bytes) -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/