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 Foundations Blocks Examples

Nicholas Lee
Nicholas Lee
12,474 Points

What does \t and \n\n do in the benchmarker example?

class SimpleBenchmarker
    def self.go(how_many=1, &block)
        puts "----------Benchmarking started----------"
        start_time = Time.now
        puts "Start Time:\t#{start_time}\n\n"
        how_many.times do |a|
            print "."
            block.call
        end
        print "\n\n"
        end_time = Time.now
        puts "End Time:\t#{end_time}"
        puts "----------Benchmarking finished----------\n\n"
        puts "Result:\t\t#{end_time - start_time} seconds"
        end
    end

    SimpleBenchmarker.go 5 do
        time = rand(0.1..1.0)
        sleep time
    end

1 Answer

\t means tab character, and \n means new line. so \n\n would be two newlines in a row. (Hint: just like hitting enter twice in your text editor.)

Stephen is correct, but on a higher level, Jason is using this to add white space to make the output more readable. Try running the code without these, and you will see that its kind of a big block of text that isn't very nice to look at.