Ruby/Hash/values at
Материал из Wiki.crossplatform.ru
Retrieve the values out of a hash based on one or more keys with values_at, also placing the value or values in an array:
zip = { 1 => "One", 2 => "Two", 3 => "Three", 4 => "Four", 5 => "Five", 6 => "Six", 7 => "Seven", 8 => "Eight", 9 => "Eight" } puts zip.values_at 5 puts zip.values_at 1, 4, 7
values_at(key) Returns an array consisting of values for the given key(s).
h = { "a" => 100, "b" => 200, "c" => 300 } h.values_at("a", "c") h.values_at("a", "c", "z") h.default = "cat" h.values_at("a", "c", "z")