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



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

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

#lazyObject



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

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

#nextObject



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

def next
  @base += progress_phase
end

#prevObject



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

def prev
  @base -= regress_phase
end