I have a hash from which I want to get specific keys
a={1=>32, 23=>23, 24=>232, 56=>123}
keys=[23,56]
To get values of this keys from a{}, I'm using function
a.values_at 23,56 # => [23, 232]`
Problem is how do I convert [23,56....]
to 23,56
Use splat operator (*
before the argument) to convert array to arguments:
a={1=>32, 23=>23, 24=>232, 56=>123}
# => {1=>32, 23=>23, 24=>232, 56=>123}
keys=[23,56]
# => [23, 56]
a.values_at(*keys)
#=> [23, 123]
See also: