From: "jeremyevans0 (Jeremy Evans)" Date: 2022-06-02T16:00:48+00:00 Subject: [ruby-core:108759] [Ruby master Bug#18815] instance_{eval, exec} vs Proc#>> Issue #18815 has been updated by jeremyevans0 (Jeremy Evans). This is basically the same as #18067. I don't think it's a bug, because you get the exact same behavior with manual composition (see example in #18067). However, I welcome feedback from other committers. ---------------------------------------- Bug #18815: instance_{eval,exec} vs Proc#>> https://bugs.ruby-lang.org/issues/18815#change-97818 * 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: