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.



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_hashObject



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