module HashConverter

Public Class Methods

encode(value, key = nil, out_hash = {}) click to toggle source

Convert a Hash (with embedded Arrays or Hashes) to something suitable for URL encoding

Attributes

  • value - Value to convert

  • key - Used internally

  • out_hash - Used internally

Returns

Array of Key / Value pairs

# File lib/onapp_market/api.rb, line 14
def self.encode(value, key = nil, out_hash = {})
  case value
  when Hash  then
    value.each { |k,v| encode(v, append_key(key,k), out_hash) }
    out_hash
  when Array then
    value.each { |v| encode(v, "#{key}[]", out_hash) }
    out_hash
  when nil   then ''
  else
    out_hash[key] = value
    out_hash
  end
end