method

values_at

v1_8_6_287 - Show latest stable - Class: Hash
values_at(...)
public

Return an array containing the values associated with the given keys. Also see Hash.select.

  h = { "cat" => "feline", "dog" => "canine", "cow" => "bovine" }
  h.values_at("cow", "cat")  #=> ["bovine", "feline"]

1Note

Passing in an Array instead of individual arguments

earless1 ยท Apr 2, 2013

Pass in array instead of list h = { "cat" => "feline", "dog" => "canine", "cow" => "bovine" }

keys_i_want = %w(cow cat)

h.values_at(*keys_i_want) #=> ["bovine", "feline"]