Class: Hash

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

Instance Method Summary collapse

Instance Method Details

#sanitize!Object



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

def sanitize!
  h = self.injecting({}) do |h, (k, v)|
        h[k] = case v
               when 'none', 'nil'; nil
               when 'true', 'yes'; true
               when 'false', 'no'; false
               else v end
      end
  self.replace h
end

#stringify_keysObject



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

def stringify_keys
  h = {}
  self.each {|k,v| h[k.to_s] = v}
  return h
end

#symbolize_keysObject



21
22
23
24
25
# File 'lib/webby/core_ext/hash.rb', line 21

def symbolize_keys
  h = {}
  self.each {|k,v| h[k.to_sym] = v}
  return h
end