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.



10
11
12
13
# File 'lib/timers/interval.rb', line 10

def initialize
	@total = 0.0
	@current = nil
end

Instance Method Details

#startObject



15
16
17
18
19
# File 'lib/timers/interval.rb', line 15

def start
	return if @current
	
	@current = now
end

#stopObject



21
22
23
24
25
26
27
# File 'lib/timers/interval.rb', line 21

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

#to_fObject



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

def to_f
	@total + duration
end