Class: JsonProjection::Fifo
- Inherits:
-
Object
- Object
- JsonProjection::Fifo
- Defined in:
- lib/json-projection/parser/fifo.rb
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #empty? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(stack = []) ⇒ Fifo
constructor
A new instance of Fifo.
- #pop! ⇒ Object
- #prepend!(fifo) ⇒ Object
- #push!(val) ⇒ Object
Constructor Details
#initialize(stack = []) ⇒ Fifo
Returns a new instance of Fifo.
12 13 14 |
# File 'lib/json-projection/parser/fifo.rb', line 12 def initialize(stack = []) @stack = stack end |
Class Method Details
.empty ⇒ Object
4 5 6 |
# File 'lib/json-projection/parser/fifo.rb', line 4 def self.empty @empty ||= self.new([].freeze) end |
.pure(*vals) ⇒ Object
8 9 10 |
# File 'lib/json-projection/parser/fifo.rb', line 8 def self.pure(*vals) Fifo.new(vals) end |
Instance Method Details
#==(other) ⇒ Object
28 29 30 31 |
# File 'lib/json-projection/parser/fifo.rb', line 28 def ==(other) return false unless other.is_a?(Fifo) return stack == other.stack end |
#empty? ⇒ Boolean
24 25 26 |
# File 'lib/json-projection/parser/fifo.rb', line 24 def empty? @stack.empty? end |
#hash ⇒ Object
33 34 35 |
# File 'lib/json-projection/parser/fifo.rb', line 33 def hash stack.hash end |
#pop! ⇒ Object
20 21 22 |
# File 'lib/json-projection/parser/fifo.rb', line 20 def pop! @stack.pop end |
#prepend!(fifo) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/json-projection/parser/fifo.rb', line 37 def prepend!(fifo) return if fifo.empty? if empty? @stack = fifo.stack.dup return end @stack = fifo.stack.concat(@stack) end |
#push!(val) ⇒ Object
16 17 18 |
# File 'lib/json-projection/parser/fifo.rb', line 16 def push!(val) @stack.insert(0, val) end |