Project

General

Profile

Actions

Feature #18369

open

users.detect(:name, "Dorian") as shorthand for users.detect { |user| user.name == "Dorian" }

Added by dorianmariefr (Dorian Marié) about 3 years ago. Updated about 3 years ago.

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

Description

Hi,

I was thinking I often do things like collection.detect { |item| item.attribute == value } and a shorthand like collection.detect(:attribute, value) would be quite useful

What do you think?

And I know there is collection.detect { _1.attribute == value } but I try not to use _1 and this syntax would be shorter and simpler

Could also apply to other methods like all? (collection.all?(:attribute, value)), and basically any Enumerable method https://rubydoc.info/stdlib/core/Enumerable

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0