In condition,
COLUMN = [:id, :tag_list, :price, :url, :Perweight, :Totalweight, :memo, :created_at, :updated_at]
row = {"id"=>4, "tag_list"=>"peanuts", "price"=>100, "Totalweight"=>390, "Perweight"=>nil, "url"=>nil, "memo"=>nil, nil=>nil}
from these two conditions, I want to make above Hash Object.
{:id=>4, :tag_list=>"peanuts", :price=>100, :Totalweight"=>390, :Perweight=>nil, :url=>nil, memo=>nil}
我试过,像这样... 首先,我制作空哈希,
new = Hash[COLUMN.zip([])]
p new
--->
{:id=>nil, :tag_list=>nil, :price=>nil, :url=>nil, :Perweight=>nil, :Totalweight=>nil, :memo=>nil, :created_at=>nil, :updated_at=>nil}
然后,我不知道该怎么做, 请给我建议?
最佳答案
关于ruby-on-rails - 使新哈希从 {"sample"=> "sample"} 到 { :sample => "sample"},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33584498/