Class: Wayfarer::Routing::HashStack

Inherits:
Object
  • Object
show all
Defined in:
lib/wayfarer/routing/hash_stack.rb

Constant Summary collapse

EmptyStackError =
Class.new(StandardError)

Class Method Summary collapse

Instance Method Summary collapse

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

.emptyObject



8
9
10
# File 'lib/wayfarer/routing/hash_stack.rb', line 8

def self.empty
  new(Route::EMPTY_PARAMS)
end

Instance Method Details

#popObject



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_hObject



24
25
26
# File 'lib/wayfarer/routing/hash_stack.rb', line 24

def to_h
  stack.last
end