开发者

Remove array inside hash

My orginal hash is like as hash = {"sku_id"=>[4], "brand_active"=>["true"], "salesman_active"=>["true"]} How to remove the array within hash. that means to convert th开发者_运维百科e hash like {"sku_id"=>4, "brand_active"=>"true", "salesman_active"=>"true"}


hash.each { |k,v| hash[k] = v[0] }


Use this function:

Hash[hash.map {|k, v| [k, *v] }]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜