Class: Betterp::TimedBlock

Inherits:
Object
  • Object
show all
Defined in:
lib/betterp/timed_block.rb

Overview

Executes a block and returns the block result and duration.

Instance Method Summary collapse

Constructor Details

#initialize(block:) ⇒ TimedBlock

Returns a new instance of TimedBlock.



6
7
8
# File 'lib/betterp/timed_block.rb', line 6

def initialize(block:)
  @block = block
end

Instance Method Details

#resultObject



10
11
12
13
14
# File 'lib/betterp/timed_block.rb', line 10

def result
  start = Time.now.utc
  block_result = block.call
  [block_result, Time.now.utc - start]
end