Class: Grape::Util::StackableValues

Inherits:
BaseInheritable show all
Defined in:
lib/grape/util/stackable_values.rb

Direct Known Subclasses

ReverseStackableValues

Instance Attribute Summary

Attributes inherited from BaseInheritable

#inherited_values, #new_values

Instance Method Summary collapse

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.



7
8
9
10
11
12
13
14
# File 'lib/grape/util/stackable_values.rb', line 7

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



16
17
18
19
# File 'lib/grape/util/stackable_values.rb', line 16

def []=(name, value)
  new_values[name] ||= []
  new_values[name].push value
end

#to_hashObject



21
22
23
24
25
# File 'lib/grape/util/stackable_values.rb', line 21

def to_hash
  keys.each_with_object({}) do |key, result|
    result[key] = self[key]
  end
end