Ruby Ruby Blocks Working With Blocks Build a Simple Benchmarker

How do I get my program to work?

class Benchmarker

  def run(&block)
    present= Time.now
    puts "This is the current time #{present}."

    yield time 
    time
    puts end_time - present
    end



 end_time= run do |time|
      Time.now
    end
 end
 benchmarker= Benchmarker.new
Brandon McClelland
Brandon McClelland
4,645 Points

Are you getting an error message (please describe if so) or asking how to run it?

bench.rb:14:in <class:Benchmarker>': undefined methodrun' for Benchmarker:Class (NoMethodError)
from bench.rb:1:in `<main>'

1 Answer

rowend rowend
rowend rowend
2,923 Points

Set out of class the next code:

    end_time= run do |time|
      Time.now
    end

And adjust to look like:

   benchmarker= Benchmarker.new
    end_time= benchmarker.run do |time|
      Time.now
    end