Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/judopay/core_ext/hash.rb
Instance Method Summary collapse
-
#camel_case_keys! ⇒ Object
Convert hash keys to camelcase.
-
#to_query_string ⇒ Object
Produce a URL query string from the hash.
Instance Method Details
#camel_case_keys! ⇒ Object
Convert hash keys to camelcase
{'this_key' => 1}.camel_case_keys! #=> { 'thisKey' => 1 }
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/judopay/core_ext/hash.rb', line 8 def camel_case_keys! output_hash = {} each do |key, value| camel_case_key = key.to_s.camel_case if value.is_a?(Hash) output_hash[camel_case_key] = value.camel_case_keys! else output_hash[key.to_s.camel_case] = value end end replace(output_hash) end |
#to_query_string ⇒ Object
Produce a URL query string from the hash
{'this_key' => 1}.to_query_string #=> this_key=1
24 25 26 27 28 |
# File 'lib/judopay/core_ext/hash.rb', line 24 def to_query_string uri = Addressable::URI.new uri.query_values = self uri.query end |