我有这个哈希和这个数组,并执行以下命令......
hash={"a"=>1,"b"=>2,"c"=>3,"d"=>4,"e"=>5,"f"=>6}
array=["b","a","c","f","z","q"]
print hash.values_at(*array).compact
所以我希望它返回如下内容:
#=> [2,1,3,6,"invalid","invalid"]
有没有办法将哈希中不存在的所有其他元素声明为“无效”,而无需一一声明(例如“g”=>“invalid”、“h”=>“invalid”...)?