Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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