Class: Wayfarer::Routing::HashStack
- Inherits:
-
Object
- Object
- Wayfarer::Routing::HashStack
- Defined in:
- lib/wayfarer/routing/hash_stack.rb
Constant Summary collapse
- EmptyStackError =
Class.new(StandardError)
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(initial_state) ⇒ HashStack
constructor
A new instance of HashStack.
- #pop ⇒ Object
- #push(hash) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(initial_state) ⇒ HashStack
Returns a new instance of HashStack.
12 13 14 |
# File 'lib/wayfarer/routing/hash_stack.rb', line 12 def initialize(initial_state) @stack = [initial_state] end |
Class Method Details
.empty ⇒ Object
8 9 10 |
# File 'lib/wayfarer/routing/hash_stack.rb', line 8 def self.empty new(Route::EMPTY_PARAMS) end |
Instance Method Details
#pop ⇒ Object
20 21 22 |
# File 'lib/wayfarer/routing/hash_stack.rb', line 20 def pop stack.pop || raise(EmptyStackError) end |
#push(hash) ⇒ Object
16 17 18 |
# File 'lib/wayfarer/routing/hash_stack.rb', line 16 def push(hash) stack.push(stack.last.dup.merge!(hash)) end |
#to_h ⇒ Object
24 25 26 |
# File 'lib/wayfarer/routing/hash_stack.rb', line 24 def to_h stack.last end |