Actions
Bug #18067
closedComposite procs with `instance_exec` aren't executed within the context of the receiver
Description
func1 = -> (x) { x + y }
class A
def y
10
end
end
A.new.instance_exec(1, &func1) # => 11
func2 = -> (x) { x * 2 }
f = func1 >> func2
A.new.instance_exec(1, &f) # => undefined local variable or method `y' for main:Object (NameError)
Updated by jeremyevans0 (Jeremy Evans) over 3 years ago
I think this is expected. You get the same error if you compose the proc manually, and the proc composition operators should reflect the same behavior as manual composition:
func1 = -> (x) { x + y }
class A
def y
10
end
end
A.new.instance_exec(1, &func1) # => 11
func2 = -> (x) { x * 2 }
f = ->(x) { func2.(func1.(x)) }
A.new.instance_exec(1, &f) # => undefined local variable or method `y' for main:Object (NameError)
Updated by jeremyevans0 (Jeremy Evans) about 3 years ago
- Status changed from Open to Rejected
Updated by jeremyevans0 (Jeremy Evans) over 2 years ago
- Has duplicate Feature #18815: instance_{eval,exec} vs Proc#>> added
Actions
Like0
Like0Like0Like0