Class: About_Pos::Enum

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/about_pos.rb

Instance Method Summary collapse

Constructor Details

#initialize(dir, arr) ⇒ Enum

Returns a new instance of Enum.



11
12
13
14
15
16
17
18
19
20
# File 'lib/about_pos.rb', line 11

def initialize dir, arr
  @arr = arr
  if dir == :forward
    @real_index = 0
  else
    @real_index = (@arr.size - 1) - 0
  end

  @meta = Meta.new(dir, @real_index, arr)
end

Instance Method Details

#eachObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/about_pos.rb', line 22

def each
  return nil if @arr.empty?
  has_next = false
  begin
    result = yield @meta.value, @meta.real_index, @meta
    has_next = @meta.next?
    if has_next
      @meta.next!
    end
  end while has_next
end