Forum: Ruby on Rails Remove array within hash

Posted by Manivannan Jeganathan (jmanivannancse)
on 2010-09-02 12:49
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"
Posted by Aleksey Gureiev (Guest)
on 2010-09-02 12:59
Attachment: PGP.sig (496 Bytes)
(Received via mailing list)
Come on, why even ask this!? Check the doc for all essentials -- Array, 
Hash, String.

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

- A
Posted by Dave Aronson (Guest)
on 2010-09-07 19:31
(Received via mailing list)
On Sep 2, 6:49 am, Manivannan Jeganathan <li...@ruby-forum.com> wrote:

> ==> hash = {"sku_id"=>[4], "brand_active"=>["true"],
> "salesman_active"=>["true"]}
>
> How to remove the array within hash.

In addition to Aleksey's response re how to UNdo the arraying, would
it be possible simply to NOT put the data in as arrays in the first
place?

-Dave
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.