[#109095] [Ruby master Misc#18888] Migrate ruby-lang.org mail services to Google Domains and Google Workspace — "shugo (Shugo Maeda)" <noreply@...>
Issue #18888 has been reported by shugo (Shugo Maeda).
16 messages
2022/06/30
[ruby-core:108759] [Ruby master Bug#18815] instance_{eval, exec} vs Proc#>>
From:
"jeremyevans0 (Jeremy Evans)" <noreply@...>
Date:
2022-06-02 16:00:48 UTC
List:
ruby-core #108759
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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>