File: rate.rb

package info (click to toggle)
ruby-mtrc 0.0.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 88 kB
  • sloc: ruby: 104; makefile: 2
file content (19 lines) | stat: -rw-r--r-- 330 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Mtrc::Rate
  # A time differential. Accumulates ticks, and provides the rate in
  # ticks/second since t0.
  attr_accessor :t0
  attr_accessor :ticks
  def initialize
    @t0 = Time.now
    @ticks = 0
  end

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

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