Class: Time
- Inherits:
-
Object
- Object
- Time
- Defined in:
- lib/freshen/helpers/time.rb
Class Method Summary collapse
-
.duration_of(&block) ⇒ Object
The total time (in seconds) for the block to complete.
Class Method Details
.duration_of(&block) ⇒ Object
The total time (in seconds) for the block to complete.
Example:
>> Time.duration_of { sleep 2 }
=> 2.000000000000001
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/freshen/helpers/time.rb', line 8 def self.duration_of(&block) return nil unless block_given? start_time = Time.now yield end_time = Time.now end_time.to_f - start_time.to_f end |