Class: Alien::AlienBlockTimer
- Inherits:
-
Object
- Object
- Alien::AlienBlockTimer
- Defined in:
- lib/alien/alienblocktimer.rb
Instance Method Summary collapse
-
#elapsed ⇒ Object
The time since we called start or since the class was initialized.
-
#initialize(description = "", &block) ⇒ AlienBlockTimer
constructor
Setup the timer and pass in an optional description.
- #inspect ⇒ Object
-
#measure(description = "", &block) ⇒ Object
Measure the execution time for an asscociated code block.
-
#start ⇒ Object
Grab a start time.
- #to_s ⇒ Object
Constructor Details
#initialize(description = "", &block) ⇒ AlienBlockTimer
Setup the timer and pass in an optional description. If there is an associated block with the call, execute a timing measurment.
70 71 72 73 74 75 76 |
# File 'lib/alien/alienblocktimer.rb', line 70 def initialize (description="",&block) @t1=Time.now @measurement = "Timer initialized." unless block.nil? measure(description){yield} end end |
Instance Method Details
#elapsed ⇒ Object
The time since we called start or since the class was initialized.
100 101 102 |
# File 'lib/alien/alienblocktimer.rb', line 100 def elapsed Time.now - @t1 end |
#inspect ⇒ Object
104 105 106 |
# File 'lib/alien/alienblocktimer.rb', line 104 def inspect @measurement end |
#measure(description = "", &block) ⇒ Object
Measure the execution time for an asscociated code block.
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/alien/alienblocktimer.rb', line 80 def measure(description="", &block) start unless block.nil? yield @measurement = description + elapsed.to_s else #Error message Haiku. :) @measurement = "No block to measure. Your timer waits patiently. Give him one to use." end end |
#start ⇒ Object
Grab a start time
95 96 97 |
# File 'lib/alien/alienblocktimer.rb', line 95 def start @t1=Time.now end |
#to_s ⇒ Object
108 109 110 |
# File 'lib/alien/alienblocktimer.rb', line 108 def to_s @measurement end |