Class: Multiples::MultiplesEnumerator
- Inherits:
-
Object
- Object
- Multiples::MultiplesEnumerator
- Defined in:
- lib/multiples/multiples_enumerator.rb
Instance Attribute Summary collapse
-
#palindrome ⇒ Object
readonly
Returns the value of attribute palindrome.
-
#phase ⇒ Object
readonly
Returns the value of attribute phase.
Instance Method Summary collapse
- #current ⇒ Object
- #each ⇒ Object
-
#initialize(palindrome) ⇒ MultiplesEnumerator
constructor
A new instance of MultiplesEnumerator.
- #lazy ⇒ Object
- #next ⇒ Object
- #prev ⇒ Object
- #reset! ⇒ Object
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
#palindrome ⇒ Object (readonly)
Returns the value of attribute palindrome.
32 33 34 |
# File 'lib/multiples/multiples_enumerator.rb', line 32 def palindrome @palindrome end |
#phase ⇒ Object (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
#current ⇒ Object
39 40 41 |
# File 'lib/multiples/multiples_enumerator.rb', line 39 def current @base end |
#each ⇒ Object
48 49 50 51 52 53 |
# File 'lib/multiples/multiples_enumerator.rb', line 48 def each loop do send :next yield @base end end |
#lazy ⇒ Object
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 |
#next ⇒ Object
61 62 63 |
# File 'lib/multiples/multiples_enumerator.rb', line 61 def next @base += progress_phase end |
#prev ⇒ Object
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 |