Class: Time

Inherits:
Object show all
Defined in:
lib/rubyexts/time.rb

Class Method Summary collapse

Class Method Details

.timer(&block) ⇒ Float

How long it takes to run the block in seconds

Examples:

Time.timer { sleep 2 } # => 2.030802

Returns:

  • (Float)

    How long it takes to run the block in seconds

Author:

  • Botanicus

Since:

  • 0.0.3



11
12
13
14
# File 'lib/rubyexts/time.rb', line 11

def self.timer(&block)
  start = Time.now.tap { block.call }
  return Time.now - start
end