How to replace a hash key with another key

后端 未结 11 1491
青春惊慌失措
青春惊慌失措 2020-12-04 07:36

I have a condition where, I get a hash

  hash = {\"_id\"=>\"4de7140772f8be03da000018\", .....}

and I want this hash as

         


        
11条回答
  •  情话喂你
    2020-12-04 08:00

    If we want to rename a specific key in hash then we can do it as follows:
    Suppose my hash is my_hash = {'test' => 'ruby hash demo'}
    Now I want to replace 'test' by 'message', then:
    my_hash['message'] = my_hash.delete('test')

提交回复
热议问题