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

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,842 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,440 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