Class: GRI::GParams
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #each ⇒ Object
- #getvar(key) ⇒ Object
-
#initialize ⇒ GParams
constructor
A new instance of GParams.
- #merge(cgi_params) ⇒ Object
- #setvar(key, value) ⇒ Object
- #update(hash) ⇒ Object
Constructor Details
#initialize ⇒ GParams
Returns a new instance of GParams.
5 6 7 |
# File 'lib/gri/gparams.rb', line 5 def initialize @params = {} end |
Instance Method Details
#[](key) ⇒ Object
21 22 23 |
# File 'lib/gri/gparams.rb', line 21 def [](key) (Array === (v = @params[key])) ? v.last : v end |
#[]=(key, value) ⇒ Object
17 18 19 |
# File 'lib/gri/gparams.rb', line 17 def []=(key, value) (@params[key] ||= []).push value end |
#each ⇒ Object
25 26 27 |
# File 'lib/gri/gparams.rb', line 25 def each @params.each {|k, v| yield k, v} end |
#getvar(key) ⇒ Object
13 14 15 |
# File 'lib/gri/gparams.rb', line 13 def getvar key @params[key] end |
#merge(cgi_params) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/gri/gparams.rb', line 34 def merge cgi_params for key, values in cgi_params for value in values self[key] = value end end end |
#setvar(key, value) ⇒ Object
9 10 11 |
# File 'lib/gri/gparams.rb', line 9 def setvar key, value @params[key] = value end |
#update(hash) ⇒ Object
29 30 31 32 |
# File 'lib/gri/gparams.rb', line 29 def update hash hash.each {|key, value| @params[key] = [value]} self end |