user2931706
user2931706

Reputation: 195

How to remove outer hash in Ruby

Let's say I've got hash like this:

{"290"=>{"id"=>"290", "name"=>"Test Number", "order"=>"2"}}

I want to to have:

{"id"=>"290", "name"=>"Test Number", "order"=>"2"}

Upvotes: 0

Views: 516

Answers (2)

Ajay
Ajay

Reputation: 4251

Please check below image: It's show different approaches to get the same result :D enter image description here

Upvotes: 0

Ivaylo Strandjev
Ivaylo Strandjev

Reputation: 70929

Let's say h = {"290"=>{"id"=>"290", "name"=>"Test Number", "order"=>"2"}}. Now you can do h = h["290"] and you will have what you want.

Upvotes: 1

Related Questions