Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/petit/core_ext.rb

Instance Method Summary collapse

Instance Method Details

#rename_key(old, new) ⇒ Object

Renames the key in a hash

Example:

h = ["a" => 100, "b" => 200]
h.rename_key("a","c")
h       # => ["c" => 100, "b" => 200]
h["c"]  # => 100


11
12
13
# File 'lib/petit/core_ext.rb', line 11

def rename_key(old,new)
  self[new] = self.delete(old)
end