Q:

filter array of hashes with an array of keys ruby

arr = [
  {
    :id=>2,
    :start=> "3:30",
    break: 30,
    num_attendees: 14
  },
  {
    id: 3,
    start: "3: 40",
    break: 40,
    num_attendees: 4
  },
  {
    id: 4,
    start: "4: 40",
    break: 10,
    num_attendees: 40
  }
]

When I do the following
arr.map do |hash|
 [ hash[:id], hash[:start] ]
end

returns
#=> [[2, "3:30"], [3, "3: 40"], [4, "4: 40"]]

Is there an elegant and efficient way of passing an array like return_keys = [:id, :start] and get the same above values rather than hard coding inside the array.map

A:

Would you consider the following elegant and efficient?
arr.map { |h| h.values_at(:id, :start) }
#=> [[2, "3:30"], [3, "3: 40"], [4, "4: 40"]]

or
arr.map { |h| h.values_at(*return_keys) }
#=> [[2, "3:30"], [3, "3: 40"], [4, "4: 40"]]

