Jes Jes - 2 years ago 113
Ruby Question

Ruby - hash to array

I have:

a = [{"_id"=>BSON::ObjectId('569a58b8e301d083c300000c')}]

and I want it to be:


I was experimenting with{|e|{|k, v| v }}

but it gives me nested array:


I'll appreciate any help.

Answer Source

If you just had a hash:

h = {"_id"=>BSON::ObjectId('569a58b8e301d083c300000c')}

and you wanted to fetch the BSON::ObectId, you would call Hash#[]:

h["_id"] #=> BSON::ObjectId('569a58b8e301d083c300000c')

The same works with map: { |h| h["_id"] }
#=> [BSON::ObjectId('569a58b8e301d083c300000c')]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download