module Enumerable
def pick(*keys)
[{ id: 1, name: "David" }, { id: 2, name: "Rafael" }].pick(:id, :name)
# => "David"
[{ name: "David" }, { name: "Rafael" }, { name: "Aaron" }].pick(:name)
Extract the given key from the first element in the enumerable.
def pick(*keys) return if none? if keys.many? keys.map { |key| first[key] } else first[keys.first] end end