instance method
pick
Ruby on Rails 7.2.3
Since v6.1.7.10Signature
pick(*keys)
Extract the given key from the first element in the enumerable.
[{ name: "David" }, { name: "Rafael" }, { name: "Aaron" }].pick(:name)
# => "David"
[{ id: 1, name: "David" }, { id: 2, name: "Rafael" }].pick(:id, :name)
# => [1, "David"]
Parameters
-
keysrest
Source
# File activesupport/lib/active_support/core_ext/enumerable.rb, line 161
def pick(*keys)
return if none?
if keys.many?
keys.map { |key| first[key] }
else
first[keys.first]
end
end
Defined in activesupport/lib/active_support/core_ext/enumerable.rb line 161
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Enumerable