Class: Mtrc::Rate
- Inherits:
-
Object
- Object
- Mtrc::Rate
- Defined in:
- lib/mtrc/rate.rb
Instance Attribute Summary collapse
-
#t0 ⇒ Object
A time differential.
-
#ticks ⇒ Object
Returns the value of attribute ticks.
Instance Method Summary collapse
-
#initialize ⇒ Rate
constructor
A new instance of Rate.
- #rate ⇒ Object
- #tick(delta = 1) ⇒ Object (also: #<<)
Constructor Details
#initialize ⇒ Rate
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
#t0 ⇒ Object
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 |
#ticks ⇒ Object
Returns the value of attribute ticks.
5 6 7 |
# File 'lib/mtrc/rate.rb', line 5 def ticks @ticks end |
Instance Method Details
#rate ⇒ Object
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 |