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.



12
13
14
15
# File 'lib/timers/interval.rb', line 12

def initialize
  @total = 0.0
  @current = nil
end

Instance Method Details

#startObject



17
18
19
20
21
# File 'lib/timers/interval.rb', line 17

def start
  return if @current
  
  @current = now
end

#stopObject



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

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

#to_fObject



31
32
33
# File 'lib/timers/interval.rb', line 31

def to_f
  @total + duration
end