[ruby-dev:51092] [Ruby master Feature#18069] `instance_exec` is just ignored when the block is originally a method
From:
nobu@...
Date:
2021-08-10 05:33:21 UTC
List:
ruby-dev #51092
Issue #18069 has been updated by nobu (Nobuyoshi Nakada).
A method is bound to the internal states of the receiver.
I don't think that removing the receiver from a method makes sense.
----------------------------------------
Feature #18069: `instance_exec` is just ignored when the block is originally a method
https://bugs.ruby-lang.org/issues/18069#change-93211
* Author: ttanimichi (Tsukuru Tanimichi)
* Status: Open
* Priority: Normal
----------------------------------------
I know you can't `instance_exec` a proc which is generated by `Method#to_proc` because it has its original instance's context. But, in such a case, raising `ArgumentError` would be the ideal behavior.
```ruby
f = -> (x) { a + x }
class A
def a
1
end
end
A.new.instance_exec(1, &f) # => 2
class B
def b(x)
a + x
end
end
proc = B.new.method(:b).to_proc
A.new.instance_exec(1, &proc) # => undefined local variable or method `a' for #<B:0x00007fdaf30480a0> (NameError)
```
--
https://bugs.ruby-lang.org/