Class: RestClient::ParamsArray

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/restclient/params_array.rb

Overview

The ParamsArray class is used to represent an ordered list of [key, value] pairs. Use this when you need to include a key multiple times or want explicit control over parameter ordering.

Most of the request payload & parameter functions normally accept a Hash of keys => values, which does not allow for duplicated keys.

Instance Method Summary collapse

Constructor Details

#initialize(array) ⇒ ParamsArray

Returns a new instance of ParamsArray.

Examples:

>> ParamsArray.new([[:foo, 123], [:foo, 456], [:bar, 789]])
This will be encoded as "foo=123&foo=456&bar=789"
>> ParamsArray.new({foo: 123, bar: 456})
This is valid, but there's no reason not to just use the Hash directly
instead of a ParamsArray.

Parameters:

  • array (Array<Array>)

    An array of parameter key,value pairs. These pairs may be 2 element arrays [key, value] or single element hashes => value. They may also be single element arrays to represent a key with no value.



31
32
33
# File 'lib/restclient/params_array.rb', line 31

def initialize(array)
  @array = process_input(array)
end

Instance Method Details

#each(*args, &blk) ⇒ Object



35
36
37
# File 'lib/restclient/params_array.rb', line 35

def each(*args, &blk)
  @array.each(*args, &blk)
end

#empty?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/restclient/params_array.rb', line 39

def empty?
  @array.empty?
end