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

Sean Ankenbruck
Sean Ankenbruck
4,196 Points

Rails Development - Ruby Numbers

Quick question here, I am using Sublime Text to follow along with this lesson and I noticed an issue with whitespace. When I try to print strings to multiple lines they are running together and I am forced to include "\n" in the string. What could be causing this? See my code below:

year = 2014 print "The year is #{year}\n" #\n is for linebreak

future = 5 print "In #{future} years, the year will be #{year + future}\n"

If I do not include the "\n" all of the lines print out as one. Any suggestions to get the desired line breaks I am seeking?

3 Answers

You can use 'puts' instead 'print'. 'puts' adds a newline to the end of the output. 'print' does not.

Reference: http://stackoverflow.com/questions/5018633/what-is-the-difference-between-print-and-puts

Sean Ankenbruck
Sean Ankenbruck
4,196 Points

The 'puts' is what I was missing. Thank you.

Michael Hulet
Michael Hulet
47,912 Points

That's not a bug; that's just the Ruby interpreter. In order to put each string on a new line in Ruby, you need to add the \n character at the beginning or end of each line

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

You can use heredoc to write multiple lines with indentation and without using the \n or \t.

http://makandracards.com/makandra/1675-using-heredoc-for-prettier-ruby-code