Bug #18067
closed
Composite procs with `instance_exec` aren't executed within the context of the receiver
Added by ttanimichi (Tsukuru Tanimichi) over 3 years ago.
Updated about 3 years ago.
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)
Related issues
1 (1 open — 0 closed)
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)
- Status changed from Open to Rejected
Also available in: Atom
PDF
Like0
Like0Like0Like0