Class: Hash

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

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#rename(candidates) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/core_ext/hash.rb', line 13

def rename(candidates)
  candidates.each do |old_key, new_key|
    self[new_key] = self.delete(old_key) if self.has_key?(old_key)
  end
  
  return self
end

#symbolize_keys!Object

Thanks merb!



4
5
6
7
8
9
10
11
# File 'lib/core_ext/hash.rb', line 4

def symbolize_keys!
  each do |k,v| 
    sym = k.respond_to?(:to_sym) ? k.to_sym : k 
    self[sym] = Hash === v ? v.symbolize_keys! : v 
    delete(k) unless k == sym
  end
  self
end