Class: Counter

Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/functional.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#cObject (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

#nextObject



36
# File 'lib/functional.rb', line 36

def next; @c += @step end

#to_fObject



38
# File 'lib/functional.rb', line 38

def to_f; c.to_f end

#to_iObject



37
# File 'lib/functional.rb', line 37

def to_i; c.to_i end