Class: TimeM::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/time_m/timer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTimer

Returns a new instance of Timer.



5
6
7
# File 'lib/time_m/timer.rb', line 5

def initialize
  @timers = {}
end

Instance Attribute Details

#timersObject (readonly)

Returns the value of attribute timers.



3
4
5
# File 'lib/time_m/timer.rb', line 3

def timers
  @timers
end

Instance Method Details

#init(name = nil) ⇒ Object



9
10
11
12
13
14
# File 'lib/time_m/timer.rb', line 9

def init(name = nil)
  @timers[name] ||= {}
  now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  @timers[name][:time] = now
  touch(name, now)
end

#reset_allObject



21
22
23
# File 'lib/time_m/timer.rb', line 21

def reset_all
  @timers = {}
end

#touch(name, time) ⇒ Object



16
17
18
19
# File 'lib/time_m/timer.rb', line 16

def touch(name, time)
  @timers[name] ||= {}
  @timers[name][:last_time] = time
end