Class: Counter
Instance Attribute Summary collapse
-
#c ⇒ Object
readonly
Returns the value of attribute c.
Instance Method Summary collapse
- #+(i) ⇒ Object
- #each(&e) ⇒ Object
-
#initialize(first = nil, step = nil) ⇒ Counter
constructor
A new instance of Counter.
- #next ⇒ Object
- #to_f ⇒ Object
- #to_i ⇒ Object
Constructor Details
#initialize(first = nil, step = nil) ⇒ Counter
Returns a new instance of Counter.
32 33 34 |
# File 'lib/functional.rb', line 32 def initialize first = nil, step = nil @c, @step = first || 0, step || 1 end |
Instance Attribute Details
#c ⇒ Object (readonly)
Returns the value of attribute c.
30 31 32 |
# File 'lib/functional.rb', line 30 def c @c end |
Instance Method Details
#+(i) ⇒ Object
40 41 42 |
# File 'lib/functional.rb', line 40 def + i @c += @step*i end |
#each(&e) ⇒ Object
44 45 46 |
# File 'lib/functional.rb', line 44 def each &e loop { e.call self; self.next } end |
#next ⇒ Object
36 |
# File 'lib/functional.rb', line 36 def next; @c += @step end |
#to_f ⇒ Object
38 |
# File 'lib/functional.rb', line 38 def to_f; c.to_f end |
#to_i ⇒ Object
37 |
# File 'lib/functional.rb', line 37 def to_i; c.to_i end |