Class: Multiples::MultiplesEnumerator

Inherits:
Object
  • Object
show all
Defined in:
lib/multiples/multiples_enumerator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(palindrome) ⇒ MultiplesEnumerator

Returns a new instance of MultiplesEnumerator.



33
34
35
36
37
# File 'lib/multiples/multiples_enumerator.rb', line 33

def initialize palindrome
  @base = 0
  @palindrome = palindrome
  @phase = 0
end

Instance Attribute Details

#palindromeObject (readonly)

Returns the value of attribute palindrome.



32
33
34
# File 'lib/multiples/multiples_enumerator.rb', line 32

def palindrome
  @palindrome
end

#phaseObject (readonly)

Returns the value of attribute phase.



32
33
34
# File 'lib/multiples/multiples_enumerator.rb', line 32

def phase
  @phase
end

Instance Method Details

#currentObject



39
40
41
# File 'lib/multiples/multiples_enumerator.rb', line 39

def current
  @base
end

#eachObject



48
49
50
51
52
53
# File 'lib/multiples/multiples_enumerator.rb', line 48

def each
  loop do
    send :next
    yield @base
  end
end

#lazyObject



55
56
57
58
59
# File 'lib/multiples/multiples_enumerator.rb', line 55

def lazy
  Enumerator::Lazy.new(self) do |yielder, *vals|
    yielder.<<(*vals)
  end
end

#nextObject



61
62
63
# File 'lib/multiples/multiples_enumerator.rb', line 61

def next
  @base += progress_phase
end

#prevObject



65
66
67
# File 'lib/multiples/multiples_enumerator.rb', line 65

def prev
  @base -= regress_phase
end

#reset!Object



43
44
45
46
# File 'lib/multiples/multiples_enumerator.rb', line 43

def reset!
  @base = 0
  @phase = 0
end