[#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:106319] [Ruby master Feature#18366] Enumerator#return_eval
From:
"matz (Yukihiro Matsumoto)" <noreply@...>
Date:
2021-11-30 02:53:04 UTC
List:
ruby-core #106319
Issue #18366 has been updated by matz (Yukihiro Matsumoto).
Status changed from Open to Rejected
* There's no real-world use case shown
* the term `eval` is not sufficient (unless it works as `eval`)
* `return` is even worse
3 strikes. Rejected. Reopen if those are addressed.
Matz.
----------------------------------------
Feature #18366: Enumerator#return_eval
https://bugs.ruby-lang.org/issues/18366#change-94949
* Author: sawa (Tsuyoshi Sawada)
* Status: Rejected
* Priority: Normal
----------------------------------------
Some `Enumerable` methods return one or more of the receiver's elements according to the return value of a block it takes. Often, we want such evaluated value rather than the original element.
For example, suppose we want to know the character width sufficient to fit all the strings in an array:
```ruby
a = ["Hello", "my", "name", "is", "Ruby"]
```
We either have to repeat the evaluation of the block:
```ruby
a.max_by(&:length).length # => 5
```
or create a temporal array:
```ruby
a.map(&:length).max # => 5
```
both of which seem not to be optimal.
I propose to have a method `Enumerator#return_eval` that returns the evaluated value(s) of the block:
```ruby
a.max_by.return_eval(&:length) # => 5
a.min_by.return_eval(&:length) # => 2
a.minmax_by.return_eval(&:length) # => [2, 5]
["Ava Davidson", "Benjamin Anderson", "Charlie Baker"]
.sort_by.return_eval{_1.split.reverse.join(", ")} # => ["Anderson, Benjamin", "Baker, Charlie", "Davidson, Ava"]
```
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>