How to create a simple timer method in Ruby that takes an arbitrary function call?
For example:
time rspec or time get_primes(54784637)
It should still return the result of the function that is passed in (get_primes).
The following doesn’t quite work:
def time block
t = Time.now
result = eval(block)
puts "\nCompleted in #{(Time.now - t).format} seconds"
result
end
Ruby 1.9.3
It’s more Rubyesque to use a block: