Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,926 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