Class: TimeM::Timer
- Inherits:
-
Object
- Object
- TimeM::Timer
- Defined in:
- lib/time_m/timer.rb
Instance Attribute Summary collapse
-
#timers ⇒ Object
readonly
Returns the value of attribute timers.
Instance Method Summary collapse
- #init(name = nil) ⇒ Object
-
#initialize ⇒ Timer
constructor
A new instance of Timer.
- #reset_all ⇒ Object
- #touch(name, time) ⇒ Object
Constructor Details
#initialize ⇒ Timer
Returns a new instance of Timer.
5 6 7 |
# File 'lib/time_m/timer.rb', line 5 def initialize @timers = {} end |
Instance Attribute Details
#timers ⇒ Object (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_all ⇒ Object
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 |