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.



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

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

Instance Attribute Details

#palindromeObject (readonly)

Returns the value of attribute palindrome.



37
38
39
# File 'lib/multiples/multiples_enumerator.rb', line 37

def palindrome
  @palindrome
end

#phaseObject (readonly)

Returns the value of attribute phase.



37
38
39
# File 'lib/multiples/multiples_enumerator.rb', line 37

def phase
  @phase
end

Instance Method Details

#currentObject



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

def current
  @base
end

#eachObject



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

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

#lazyObject



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

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

#nextObject



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

def next
  @base += progress_phase
end

#prevObject



70
71
72
# File 'lib/multiples/multiples_enumerator.rb', line 70

def prev
  @base -= regress_phase
end

#reset!Object



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

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