Class: Timers::Interval

Inherits:
Object
  • Object
show all
Defined in:
lib/timers/interval.rb

Overview

A collection of timers which may fire at different times

Instance Method Summary collapse

Constructor Details

#initializeInterval

Get the current elapsed monotonic time.



27
28
29
30
# File 'lib/timers/interval.rb', line 27

def initialize
  @total = 0.0
  @current = nil
end

Instance Method Details

#startObject



32
33
34
35
36
# File 'lib/timers/interval.rb', line 32

def start
  return if @current
  
  @current = now
end

#stopObject



38
39
40
41
42
43
44
# File 'lib/timers/interval.rb', line 38

def stop
  return unless @current
  
  @total += duration
  
  @current = nil
end

#to_fObject



46
47
48
# File 'lib/timers/interval.rb', line 46

def to_f
  @total + duration
end