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 Block Method Practice: Custom Classes

Jessica H
Jessica H
16,612 Points

Benchmarker Error

Why is the code not working and what am I missing here?

I want to add in the space between "elapsed" and the puts statement:

benchmarker = SimpleBenchMarker.new

but it does not recognize the variable at all.

I also tried adding above @benchmarker, attr_reader and a couple of other combinations and this isn"t working.

Idea?

simple_benchmarker.rb
class SimpleBenchmarker
  def run(description, &block)
    start_time = Time.now
    block.call
    end_time = Time.now
    elapsed = end_time - start_time

    puts "\n#{description} results"
    puts "Elapsed time: #{elapsed} seconds"
  end
end

4 Answers

William Li
PLUS
William Li
Courses Plus Student 26,867 Points

benchmarker = SimpleBenchMarker.new, there's typo here, it's SimpleBenchmarker, m in lowercase.

Jessica H
Jessica H
16,612 Points

Sorry I tried it with lower case m and it is still not working.

((Bummer! The benchmarker variable was not found.))

William Li
William Li
Courses Plus Student 26,867 Points
benchmarker = SimpleBenchmarker.new

not every letter in lower case.

Jessica H
Jessica H
16,612 Points

Something is wrong with the form.

I did not use all lower case. I put "SimpleBenchmarker.new" I also copy/paste your answer there.

((Same error: Bummer! The benchmarker variable was not found.))

Why is it not finding the new variable? I am trying to define it by call the new method on SimpleBenchmarker. Is something wrong with the website? Maybe a bug if it can not recognize what I'm doing...

I also already passed other challenges after this one. Only this challenge is stopping me from getting the badge.

William Li
William Li
Courses Plus Student 26,867 Points
class SimpleBenchmarker
  def run(description, &block)
    start_time = Time.now
    block.call
    end_time = Time.now
    elapsed = end_time - start_time

    puts "\n#{description} results"
    puts "Elapsed time: #{elapsed} seconds"
  end
end

benchmarker = SimpleBenchmarker.new

Don't tell me copy/paste this entire code there don't get you pass the part 1. :smirk:

William Li
PLUS
William Li
Courses Plus Student 26,867 Points

btw, you should not change anything within class definition