标签: ruby hash
我的代码是
a={"1"=>"adi","2"=>"amar","3"=>"rave","4"=>"sum"} arr=["1","5","3"]
如果哈希
result =["adi","rave"]
不使用任何循环。是否可能
答案 0 :(得分:29)
你可以这样做:
a.values_at(*arr).compact # => ["adi", "rave"]