Module: QueryParams

Defined in:
lib/queryparams.rb,
lib/queryparams/version.rb

Constant Summary collapse

VERSION =
"0.0.3"

Class Method Summary collapse

Class Method Details

.encode(value, key = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/queryparams.rb', line 6

def self.encode(value, key = nil)
  case value
  when Hash  then value.map { |k,v| encode(v, append_key(key,k)) }.join('&')
  when Array then value.map { |v| encode(v, "#{key}[]") }.join('&')
  when nil   then ''
  else            
    "#{key}=#{CGI.escape(value.to_s)}" 
  end
end