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 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,868 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,868 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,868 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,868 Points

btw, you should not change anything within class definition