Mich
Mich

Reputation: 749

Hash manipulation in Ruby

Quick ruby question regarding the manipulation of a Hash in Ruby.

I actually have the following hash:

[2] project(#<V1::UsersController>) »  error.info
=> {
        :id => "914a24888-5e71-4d12-b9b0-10e2d98f516b",
      :game => "vampotron",
      :data => {
    "private" => {
          "name" => "Jean",
        "logins" => 2300,
           "foo" => "bar"
    }
  },
  :revision => 1
}

I want the hash to become:

[2] project(#<V1::UsersController>) »  error.info
=> {
        :id => "914a24888-5e71-4d12-b9b0-10e2d98f516b",
      :game => "vampotron",
      :data => {
          "name" => "Jean",
        "logins" => 2300,
           "foo" => "bar"
      },
      :revision => 1
}

I would like to remove the 'private' key by keeping the existing k,v pairs in my 'data' hash.

Thanks for your help,

M

Upvotes: 0

Views: 501

Answers (1)

djaszczurowski
djaszczurowski

Reputation: 4523

The easiest way

hash[:data] = hash[:data]['private']

Upvotes: 2

Related Questions