From: ctm@... Date: 2014-11-14T22:29:50+00:00 Subject: [ruby-core:66287] [ruby-trunk - misc #10513] [Open] instance_eval yields the receiver, but is documented to yield no arguments Issue #10513 has been reported by Cliff Matthews. ---------------------------------------- misc #10513: instance_eval yields the receiver, but is documented to yield no arguments https://bugs.ruby-lang.org/issues/10513 * Author: Cliff Matthews * Status: Open * Priority: Low * Assignee: Zachary Scott * Category: doc * Target version: ---------------------------------------- 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/