Actions
Feature #18815
openinstance_{eval,exec} vs Proc#>>
Status:
Open
Assignee:
-
Target version:
-
Description
measure = proc { p "self=#{self}"; size }
multiply = proc { '*' * _1 }
'test'.instance_eval(&measure)
# "self=test"
# => 4
'test'.instance_eval(&measure >> multiply)
# "self=main"
# NameError (undefined local variable or method `size' for main:Object)
So, Proc#>>
produces a proc which is not suitable for instance_eval
/instance_exec
. The same as the "naive" implementation:
# Naive sequence
sequence = proc { measure.call.then(&multiply) }
...but is it possible to make the combination to behave like the first proc is not wrapped into an additional layer of indirection?.. Intuitively, it shouldn't be completely impossible.
# What I meant actually:
intended = proc { size.then(&multilpy) }
"test".instance_eval(&intended)
# => "****"
The example is invented, the question is "whether this should work", not "how to solve this task with another approach".
Actions
Like0
Like0Like0Like0Like0