Class: Hash

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

Instance Method Summary collapse

Instance Method Details

#stringfy_keys!Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ext/hash.rb', line 26

def stringfy_keys!
  self.each do |key, value|
    unless self.delete(key.to_sym).nil?
      if value.is_a?(Hash)
        value.stringfy_keys!
      elsif value.is_a?(Array)
        value.map!{ |v| v.stringfy_keys! if v.is_a?(Hash) }
      end
      self[key.to_s] = value
    end
  end  
  self  
end

#stringfy_values!Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ext/hash.rb', line 40

def stringfy_values!
  self.each do |key, value|
    if value.is_a?(Hash)
      value.stringfy_values!
    elsif value.is_a?(Array)
      value.map!{ |v| v.stringfy_values! if v.is_a?(Hash) }
    end
    self[key] = value.to_s
  end  
  self
end

#symbolize_keys!Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ext/hash.rb', line 12

def symbolize_keys!
  self.each do |key, value|
    unless self.delete(key.to_s).nil?
      if value.is_a?(Hash)
        value.symbolize_keys!
      elsif value.is_a?(Array)
        value.map!{ |v| v.symbolize_keys! if v.is_a?(Hash) }
      end
      self[key.to_sym] = value
    end
  end  
  self
end

#to_http_strObject



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

def to_http_str
  result = ''
  return result if self.empty?
  self.each do |key, val|
    result << "#{key}=#{URI.encode(val.to_s)}&"
  end
  result.chop
end