Class: Maze::Timer

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

Overview

A simple run/stop timer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTimer

Returns a new instance of Timer.



7
8
9
# File 'lib/maze/timers.rb', line 7

def initialize
  @total = 0
end

Instance Attribute Details

#totalObject

Returns the value of attribute total.



5
6
7
# File 'lib/maze/timers.rb', line 5

def total
  @total
end

Instance Method Details

#resetObject



19
20
21
# File 'lib/maze/timers.rb', line 19

def reset
  @total = 0
end

#time(&block) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/maze/timers.rb', line 11

def time(&block)
  start = Time.now

  block.call
ensure
  @total += Time.now - start
end