Returns a URL-encoded string derived from the given Enumerable enum
.
The result is suitable for use as form data for an HTTP request whose Content-Type
is 'application/x-www-form-urlencoded'
.
The returned string consists of the elements of enum
, each converted to one or more URL-encoded strings, and all joined with character '&'
.
Simple examples:
Gem::URI.encode_www_form([['foo', 0], ['bar', 1], ['baz', 2]])
Gem::URI.encode_www_form({foo: 0, bar: 1, baz: 2})
The returned string is formed using method Gem::URI.encode_www_form_component, which converts certain characters:
Gem::URI.encode_www_form('f#o': '/', 'b-r': '$', 'b z': '@')
When enum
is Array-like, each element ele
is converted to a field:
If ele
is an array of two or more elements, the field is formed from its first two elements (and any additional elements are ignored):
name = Gem::URI.encode_www_form_component(ele[0], enc)
value = Gem::URI.encode_www_form_component(ele[1], enc)
"#{name}=#{value}"
Examples:
Gem::URI.encode_www_form([%w[foo bar], %w[baz bat bah]])
Gem::URI.encode_www_form([['foo', 0], ['bar', :baz, 'bat']])
If ele
is an array of one element, the field is formed from ele[0]
:
Gem::URI.encode_www_form_component(ele[0])
Example:
Gem::URI.encode_www_form([['foo'], [:bar], [0]])
Otherwise the field is formed from ele
:
Gem::URI.encode_www_form_component(ele)
Example:
Gem::URI.encode_www_form(['foo', :bar, 0])
The elements of an Array-like enum
may be mixture:
Gem::URI.encode_www_form([['foo', 0], ['bar', 1, 2], ['baz'], :bat])
When enum
is Hash-like, each key
/value
pair is converted to one or more fields:
If value
is Array-convertible, each element ele
in value
is paired with key
to form a field:
name = Gem::URI.encode_www_form_component(key, enc)
value = Gem::URI.encode_www_form_component(ele, enc)
"#{name}=#{value}"
Example:
Gem::URI.encode_www_form({foo: [:bar, 1], baz: [:bat, :bam, 2]})
Otherwise, key
and value
are paired to form a field:
name = Gem::URI.encode_www_form_component(key, enc)
value = Gem::URI.encode_www_form_component(value, enc)
"#{name}=#{value}"
Example:
Gem::URI.encode_www_form({foo: 0, bar: 1, baz: 2})
The elements of a Hash-like enum
may be mixture:
Gem::URI.encode_www_form({foo: [0, 1], bar: 2})
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4