Class: FibonacciEnumerator
- Inherits:
-
Object
- Object
- FibonacciEnumerator
- Extended by:
- Enumerable
- Includes:
- Enumerable
- Defined in:
- lib/fibonacci_enumerator.rb,
lib/fibonacci_enumerator/version.rb
Overview
rubocop:disable Style/StaticClass
Constant Summary collapse
- VERSION =
'0.1.0'
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
Class Method Summary collapse
Instance Method Summary collapse
- #at(index) ⇒ Integer
- #each {|| ... } ⇒ Enumerator, self
-
#initialize ⇒ FibonacciEnumerator
constructor
A new instance of FibonacciEnumerator.
- #reset_cache ⇒ void
Constructor Details
#initialize ⇒ FibonacciEnumerator
Returns a new instance of FibonacciEnumerator.
35 36 37 |
# File 'lib/fibonacci_enumerator.rb', line 35 def initialize reset_cache end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
33 34 35 |
# File 'lib/fibonacci_enumerator.rb', line 33 def cache @cache end |
Class Method Details
.[] ⇒ Object
22 23 24 |
# File 'lib/fibonacci_enumerator.rb', line 22 def at(index) new.at(index) end |
.at(index) ⇒ Object
19 20 21 |
# File 'lib/fibonacci_enumerator.rb', line 19 def at(index) new.at(index) end |
.each {|| ... } ⇒ Enumerator, self
26 27 28 |
# File 'lib/fibonacci_enumerator.rb', line 26 def each(&block) new.each(&block) end |
Instance Method Details
#at(index) ⇒ Integer
41 42 43 44 45 |
# File 'lib/fibonacci_enumerator.rb', line 41 def at(index) return at_int(index) if index.is_a?(::Integer) at_range(index) end |
#each {|| ... } ⇒ Enumerator, self
49 50 51 52 53 54 55 56 57 |
# File 'lib/fibonacci_enumerator.rb', line 49 def each return enum_for(:each) unless block_given? (0..).each do |i| yield at_int(i) end self end |
#reset_cache ⇒ void
This method returns an undefined value.
60 61 62 |
# File 'lib/fibonacci_enumerator.rb', line 60 def reset_cache @cache = [0, 1, 1] end |