Module: URI::QueryHash

Defined in:
lib/uri/query_hash.rb

Overview

Extends a hash with query string rendering/semi-indifferent access

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](value) ⇒ Object

Creates a new hash populated with the given objects.



17
18
19
20
21
# File 'lib/uri/query_hash.rb', line 17

def self.[](value)
  Hash[value].tap do |hash|
    hash.extend(QueryHash)
  end
end

Instance Method Details

#[](key) ⇒ Object



5
6
7
8
9
# File 'lib/uri/query_hash.rb', line 5

def [](key)
  item = super key
  item = super(key.to_s) if item.nil? || item.empty?
  item.instance_of?(Array) && item.empty? ? nil : item
end

#to_sObject



11
12
13
# File 'lib/uri/query_hash.rb', line 11

def to_s
  keys.map { |key| render_value(key, self[key]) }.join("&")
end