Class: Rack::QueryParser::Params
- Inherits:
-
Object
- Object
- Rack::QueryParser::Params
- Defined in:
- lib/rack/query_parser.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize ⇒ Params
constructor
A new instance of Params.
- #key?(key) ⇒ Boolean
-
#to_h ⇒ Object
(also: #to_params_hash)
Recursively unwraps nested ‘Params` objects and constructs an object of the same shape, but using the objects’ internal representations (Ruby hashes) in place of the objects.
Constructor Details
#initialize ⇒ Params
Returns a new instance of Params.
198 199 200 201 |
# File 'lib/rack/query_parser.rb', line 198 def initialize @size = 0 @params = {} end |
Instance Method Details
#[](key) ⇒ Object
203 204 205 |
# File 'lib/rack/query_parser.rb', line 203 def [](key) @params[key] end |
#[]=(key, value) ⇒ Object
207 208 209 |
# File 'lib/rack/query_parser.rb', line 207 def []=(key, value) @params[key] = value end |
#key?(key) ⇒ Boolean
211 212 213 |
# File 'lib/rack/query_parser.rb', line 211 def key?(key) @params.key?(key) end |
#to_h ⇒ Object Also known as: to_params_hash
Recursively unwraps nested ‘Params` objects and constructs an object of the same shape, but using the objects’ internal representations (Ruby hashes) in place of the objects. The result is a hash consisting purely of Ruby primitives.
Mutation warning!
1. This method mutates the internal representation of the `Params`
objects in order to save object allocations.
2. The value you get back is a reference to the internal hash
representation, not a copy.
3. Because the `Params` object's internal representation is mutable
through the `#[]=` method, it is not thread safe. The result of
getting the hash representation while another thread is adding a
key to it is non-deterministic.
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/rack/query_parser.rb', line 233 def to_h @params.each do |key, value| case value when self # Handle circular references gracefully. @params[key] = @params when Params @params[key] = value.to_h when Array value.map! { |v| v.kind_of?(Params) ? v.to_h : v } else # Ignore anything that is not a `Params` object or # a collection that can contain one. end end @params end |