Class: Mtrc::Rate

Inherits:
Object
  • Object
show all
Defined in:
lib/mtrc/rate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRate

Returns a new instance of Rate.



6
7
8
9
# File 'lib/mtrc/rate.rb', line 6

def initialize
  @t0 = Time.now
  @ticks = 0
end

Instance Attribute Details

#t0Object

A time differential. Accumulates ticks, and provides the rate in ticks/second since t0.



4
5
6
# File 'lib/mtrc/rate.rb', line 4

def t0
  @t0
end

#ticksObject

Returns the value of attribute ticks.



5
6
7
# File 'lib/mtrc/rate.rb', line 5

def ticks
  @ticks
end

Instance Method Details

#rateObject



11
12
13
# File 'lib/mtrc/rate.rb', line 11

def rate
  @ticks / (Time.now - @t0)
end

#tick(delta = 1) ⇒ Object Also known as: <<



15
16
17
# File 'lib/mtrc/rate.rb', line 15

def tick(delta = 1)
  @ticks += delta
end