[#106341] [Ruby master Bug#18369] users.detect(:name, "Dorian") as shorthand for users.detect { |user| user.name == "Dorian" } — dorianmariefr <noreply@...>
Issue #18369 has been reported by dorianmariefr (Dorian Mari辿).
14 messages
2021/11/30
[#106351] [Ruby master Bug#18371] Release branches (release information in general) — "tenderlovemaking (Aaron Patterson)" <noreply@...>
Issue #18371 has been reported by tenderlovemaking (Aaron Patterson).
7 messages
2021/11/30
[ruby-core:106078] [Ruby master Feature#18276] `Proc#bind_call(obj)` same as `obj.instance_exec(..., &proc_obj)`
From:
"ko1 (Koichi Sasada)" <noreply@...>
Date:
2021-11-16 06:23:20 UTC
List:
ruby-core #106078
Issue #18276 has been updated by ko1 (Koichi Sasada).
Dan0042 (Daniel DeLorme) wrote in #note-6:
> Why not `proc.bind(obj).call` ? It seems a more "proper" API, more composable. You can bind once and then call multiple times. Maybe `Ractor.make_shareable(proc.bind(nil))`. I understand the performance benefit of `bind_call` but in #15955, UnboundMethod#bind_call was introduced as an optimization for hot spots, to be used by "only some fundamental libraries".
`Proc#bind(obj)` returns new Proc or modify the Proc (mutate the Proc)?
----------------------------------------
Feature #18276: `Proc#bind_call(obj)` same as `obj.instance_exec(..., &proc_obj)`
https://bugs.ruby-lang.org/issues/18276#change-94667
* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
----------------------------------------
`Proc#bind_call(obj)` same as `obj.instance_exec(..., &proc_obj)`
```ruby
proc_obj = proc{|params...| ...}
obj.instance_exec(params..., &proc_obj)
```
is frequent pattern.
```
$ gem-codesearch 'instance_exec.+\&' | wc -l
9558
```
How about to introduce new method `Proc#bind_call`?
```ruby
class Proc
def bind_call obj, *args
obj.instance_exec(*args, &self)
end
end
pr = ->{ p self }
pr.bind_call("hello") #=> "hello"
pr.bind_call(nil) #=> nil
```
It is similar to `UnboundMethod#bind_call`.
----
My motivation;
I want to solve shareable Proc's issue https://bugs.ruby-lang.org/issues/18243 and one idea is to prohibit `Proc#call` for shareable Proc's, but allow `obj.instance_exec(&pr)`. To make shortcut, I want to introduce `Proc#bind_call`.
`UnboundProc` is another idea, but I'm not sure it is good idea...
Anyway, we found that there are many usage of `instance_exec(&proc_obj)`, so `Proc#bind_call` is useful not for Ractors.
--
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>