How to replace a hash key with another key

后端 未结 11 1498
青春惊慌失措
青春惊慌失措 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 07:50

    rails Hash has standard method for it:

    hash.transform_keys{ |key| key.to_s.upcase }
    

    http://api.rubyonrails.org/classes/Hash.html#method-i-transform_keys

    UPD: ruby 2.5 method

提交回复
热议问题