Module: Wesabe::Extensions::Hash
- Included in:
- Hash
- Defined in:
- lib/wesabe/extensions.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#to_http_query_str(opts = {}) ⇒ Object
Returns string formatted for HTTP URL encoded name-value pairs.
Class Method Details
.included(klass) ⇒ Object
31 32 33 |
# File 'lib/wesabe/extensions.rb', line 31 def self.included(klass) klass.extend(ClassMethods) if klass.kind_of?(Class) end |
Instance Method Details
#to_http_query_str(opts = {}) ⇒ 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"
44 45 46 47 48 |
# File 'lib/wesabe/extensions.rb', line 44 def to_http_query_str(opts = {}) opts[:prepend] ||= '?' opts[:append] ||= '' self.empty? ? '' : "#{opts[:prepend]}#{self.collect{|key, val| "#{key.to_s}=#{CGI.escape(val.to_s)}"}.join('&')}#{opts[:append]}" end |