Class: Hash
Instance Method Summary collapse
-
#recursive_symbolize_keys! ⇒ Hash
Recursively Symbolize Keys!.
-
#symbolize_keys ⇒ Hash
Symbolize Keys.
-
#symbolize_keys! ⇒ Hash
Symbolize Keys!.
-
#to_query(namespace = nil) ⇒ String
To query.
Instance Method Details
#recursive_symbolize_keys! ⇒ Hash
Recursively Symbolize Keys!
48 49 50 51 52 53 |
# File 'lib/core_ext/hash.rb', line 48 def recursive_symbolize_keys! symbolize_keys! values.each{|h| h.recursive_symbolize_keys! if h.is_a?(Hash) } values.select{|v| v.is_a?(Array) }.flatten.each{|h| h.recursive_symbolize_keys! if h.is_a?(Hash) } self end |
#symbolize_keys ⇒ Hash
Symbolize Keys
23 24 25 26 27 28 |
# File 'lib/core_ext/hash.rb', line 23 def symbolize_keys inject({}) do |, (key, value)| [(key.to_sym rescue key) || key] = value end end |
#symbolize_keys! ⇒ Hash
Symbolize Keys!
37 38 39 |
# File 'lib/core_ext/hash.rb', line 37 def symbolize_keys! self.replace(self.symbolize_keys) end |
#to_query(namespace = nil) ⇒ String
To query
10 11 12 13 14 |
# File 'lib/core_ext/hash.rb', line 10 def to_query(namespace = nil) collect do |key, value| value.to_query(namespace ? "#{namespace}[#{key}]" : key) end.sort * '&' end |