Class: Hash

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

Instance Method Summary collapse

Instance Method Details

#stringify_keysObject



14
15
16
# File 'lib/small/hash.rb', line 14

def stringify_keys
  transform_keys(&:to_s)
end

#stringify_keys!Object



18
19
20
# File 'lib/small/hash.rb', line 18

def stringify_keys!
  transform_keys!(&:to_s)
end

#symbolize_keysObject



22
23
24
# File 'lib/small/hash.rb', line 22

def symbolize_keys
  transform_keys(&:to_sym)
end

#symbolize_keys!Object



26
27
28
# File 'lib/small/hash.rb', line 26

def symbolize_keys!
  transform_keys!(&:to_sym)
end

#to_paramObject



30
31
32
# File 'lib/small/hash.rb', line 30

def to_param
  collect {|key, value| "#{key}=#{value}" }.sort * '&'
end

#transform_keysObject



3
4
5
6
7
# File 'lib/small/hash.rb', line 3

def transform_keys
  result = {}
  keys.each {|key| result[(yield(key) rescue key)] = self[key] }
  result
end

#transform_keys!Object



9
10
11
12
# File 'lib/small/hash.rb', line 9

def transform_keys!
  keys.each {|key| self[(yield(key) rescue key)] = delete(key)}
  self
end