From: "zverok (Victor Shepelev)" Date: 2022-06-02T12:58:04+00:00 Subject: [ruby-core:108757] [Ruby master Bug#18815] instance_{eval, exec} vs Proc#>> Issue #18815 has been reported by zverok (Victor Shepelev). ---------------------------------------- Bug #18815: instance_{eval,exec} vs Proc#>> https://bugs.ruby-lang.org/issues/18815 * Author: zverok (Victor Shepelev) * Status: Open * Priority: Normal * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- ```ruby 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: ```ruby # 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. ```ruby # 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". -- https://bugs.ruby-lang.org/ Unsubscribe: