Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/vendor/twitter/lib/twitter/ext/stdlib.rb,
lib/cerberus/utils.rb
Overview
Extension to Hash to create URL encoded string from key-values
Direct Known Subclasses
Instance Method Summary collapse
- #deep_merge!(second) ⇒ Object
-
#to_http_str ⇒ Object
Returns string formatted for HTTP URL encoded name-value pairs.
Instance Method Details
#deep_merge!(second) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/cerberus/utils.rb', line 81 def deep_merge!(second) second.each_pair do |k,v| if self[k].is_a?(Hash) and second[k].is_a?(Hash) self[k].deep_merge!(second[k]) else self[k] = second[k] end end end |
#to_http_str ⇒ Object
Returns string formatted for HTTP URL encoded name-value pairs. For example,
{:id => 'thomas_hardy'}.to_http_str
# => "id=thomas_hardy"
{:id => 23423, :since => Time.now}.to_http_str
# => "since=Thu,%2021%20Jun%202007%2012:10:05%20-0500&id=23423"
11 12 13 14 15 16 17 18 |
# File 'lib/vendor/twitter/lib/twitter/ext/stdlib.rb', line 11 def to_http_str result = '' return result if self.empty? self.each do |key, val| result << "#{key}=#{CGI.escape(val.to_s)}&" end result.chop # remove the last '&' character, since it can be discarded end |