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.
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
#palindrome ⇒ Object (readonly)
Returns the value of attribute palindrome.
37 38 39 |
# File 'lib/multiples/multiples_enumerator.rb', line 37 def palindrome @palindrome end |
#phase ⇒ Object (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
#current ⇒ Object
44 45 46 |
# File 'lib/multiples/multiples_enumerator.rb', line 44 def current @base end |
#each ⇒ Object
53 54 55 56 57 58 |
# File 'lib/multiples/multiples_enumerator.rb', line 53 def each loop do send :next yield @base end end |
#lazy ⇒ Object
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 |
#next ⇒ Object
66 67 68 |
# File 'lib/multiples/multiples_enumerator.rb', line 66 def next @base += progress_phase end |
#prev ⇒ Object
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 |