# Contains Ruby standard library extensions specific to Twitter4R library. # Extension to Hash to create URL encoded string from key-values class Hash # 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" 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 # remove the last '&' character, since it can be discarded end end # Extension to Time that outputs RFC2822 compliant string on #to_s class Time alias :old_to_s :to_s # Returns RFC2822 compliant string for Time object. # For example, # # Tony Blair's last day in office (hopefully) # best_day_ever = Time.local(2007, 6, 27) # best_day_ever.to_s # => "Wed, 27 Jun 2007 00:00:00 +0100" def to_s self.rfc2822 end end