Manivannan j
Manivannan j

Reputation: 21

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 the hash like {"sku_id"=>4, "brand_active"=>"true", "salesman_active"=>"true"}

Upvotes: 1

Views: 236

Answers (2)

Jörg W Mittag
Jörg W Mittag

Reputation: 369594

Use this function:

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

Upvotes: 1

Manivannan j
Manivannan j

Reputation: 21

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

Upvotes: 1

Related Questions