开发者

Remove array inside hash

开发者 https://www.devze.com 2023-01-14 18:26 出处:网络
My orginal hash is like as hash = {\"sku_id\"=>[4], \"brand_active\"=>[\"true\"], \"salesman_active\"=>[\"true\"]}

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

精彩评论

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

关注公众号