Class: Grape::Util::StackableValues
- Inherits:
-
BaseInheritable
- Object
- BaseInheritable
- Grape::Util::StackableValues
- Defined in:
- lib/grape/util/stackable_values.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from BaseInheritable
#inherited_values, #new_values
Instance Method Summary collapse
-
#[](name) ⇒ Object
Even if there is no value, an empty array will be returned.
- #[]=(name, value) ⇒ Object
- #to_hash ⇒ Object
Methods inherited from BaseInheritable
#delete, #initialize, #initialize_copy, #key?, #keys
Constructor Details
This class inherits a constructor from Grape::Util::BaseInheritable
Instance Method Details
#[](name) ⇒ Object
Even if there is no value, an empty array will be returned.
9 10 11 12 13 14 15 16 |
# File 'lib/grape/util/stackable_values.rb', line 9 def [](name) inherited_value = inherited_values[name] new_value = new_values[name] return new_value || [] unless inherited_value concat_values(inherited_value, new_value) end |
#[]=(name, value) ⇒ Object
18 19 20 21 |
# File 'lib/grape/util/stackable_values.rb', line 18 def []=(name, value) new_values[name] ||= [] new_values[name].push value end |
#to_hash ⇒ Object
23 24 25 26 27 |
# File 'lib/grape/util/stackable_values.rb', line 23 def to_hash keys.each_with_object({}) do |key, result| result[key] = self[key] end end |