Project

General

Profile

Actions

Feature #18815

open

instance_{eval,exec} vs Proc#>>

Added by zverok (Victor Shepelev) over 2 years ago. Updated over 2 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:108757]

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".


Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Bug #18067: Composite procs with `instance_exec` aren't executed within the context of the receiverRejectedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0