Get multiple values ββfrom a hash in a very efficient way
My code
a={"1"=>"adi","2"=>"amar","3"=>"rave","4"=>"sum"} arr=["1","5","3"] I want to extract all values ββlike this if array values ββexist in hash
result =["adi","rave"] without using any cycle. Is it possible
+8
Ravendra kumar
source share1 answer
You can do:
a.values_at(*arr).compact # => ["adi", "rave"] +27
toro2k
source share