Actions
Bug #19888
closedCan't change binding of a Proc coerced from a Method
Description
instance_exec
or instance_eval
can execute a given Proc
in the context of the receiver. However, that's not true when the Proc
has been coerced from a Method
. In that situation, the binding is always tied to the original instance.
class A
def foo
"from A"
end
end
class B
def foo
"from B"
end
end
A.new.instance_exec(&-> { foo }) # => from A
A.new.instance_exec(&B.new.method(:foo)) # => from B
A.new.instance_exec(&B.new.method(:foo).to_proc) # => from B
At first sight, that looks like a bug, as the transformation from Method
to Proc
is not complete.
Actions
Like0
Like0