| In: |
iterator.rb
|
| Parent: | Iterator::Base |
require 'iterator' ary1 = %w(a b c) i1 = ary1.create_iterator iterator = Iterator::ProxyLast.new(i1) result = [] while iterator.has_next? result << [iterator.last_value, iterator.current] iterator.next end iterator.close i1.close p result # [[nil, "a"], ["a", "b"], ["b", "c"]]
This class is bidirectional, so reverse is therefore possible.
| i | [R] | iterator that is wrapped by us |
| last_value | [R] | caching of the last element |
Create an instance of ProxyLast. Must supplied an iterator. The last_value is optional, and is only being used in the first iteration.
i1 = "hello".split(//).create_iterator iterator = Iterator::ProxyLast.new(i1, 'border')