Issue #15975 has been updated by phluid61 (Matthew Kerwin).


Apologies for posting to a closed ticket, but here's a thought in case it helps someone propose something else in future: partial application in #to_proc , e.g. `games.map(&(:[], :steam_id))`

I hate the syntax I just invented, but the idea of partial application to the right (i.e. applying args to a proc before applying the receiver) is interesting.

----------------------------------------
Feature #15975: Add Array#pluck
https://bugs.ruby-lang.org/issues/15975#change-88952

* Author: lewispb (Lewis Buckley)
* Status: Rejected
* Priority: Normal
----------------------------------------
Inspired by https://github.com/rails/rails/issues/20339

While developing web applications I've often wanted to quickly extract an array of values from an array of hashes.

With an array of objects, this is possible:

```rb
irb(main):001:0> require 'ostruct'
=> true
irb(main):002:0> [OpenStruct.new(name: "Lewis")].map(&:name)
=> ["Lewis"]
```

This PR adds Array#pluck allowing this:

```rb
irb(main):001:0> [ {name: "Lewis"} ].pluck(:name)
=> ["Lewis"]
```

without this PR:

```rb
irb(main):001:0> [ {name: "Lewis"} ].map { |item| item[:name] }
=> ["Lewis"]
```

Implemented here:

https://github.com/ruby/ruby/pull/2263



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