Module: Layo::Peekable
Instance Attribute Summary collapse
-
#peek_index ⇒ Object
Returns the value of attribute peek_index.
Instance Method Summary collapse
Instance Attribute Details
#peek_index ⇒ Object
Returns the value of attribute peek_index.
3 4 5 |
# File 'lib/layo/peekable.rb', line 3 def peek_index @peek_index end |
Instance Method Details
#next ⇒ Object
21 22 23 24 25 |
# File 'lib/layo/peekable.rb', line 21 def next @peek_index = -1 @items << next_item if @items.empty? @items.shift end |
#peek ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/layo/peekable.rb', line 9 def peek @peek_index += 1 while @items.length <= @peek_index @items << next_item end @items[@peek_index] end |
#reset ⇒ Object
5 6 7 |
# File 'lib/layo/peekable.rb', line 5 def reset @peek_index, @items = -1, [] end |
#reset_peek ⇒ Object
27 28 29 |
# File 'lib/layo/peekable.rb', line 27 def reset_peek @peek_index = -1 end |
#unpeek ⇒ Object
17 18 19 |
# File 'lib/layo/peekable.rb', line 17 def unpeek @peek_index -= 1 if @peek_index > -1 end |