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 Basics (Retired) How Ruby Works Input and Output

Paul M
Paul M
16,370 Points

Why does using a variable with GETS skips a line in the console? And why did Jason use print instead of puts?

I saw when using a variable with GETS skips a line in the console, And why did Jason use print instead of puts to display the prompt for name?

1 Answer

John Steer-Fowler
PLUS
John Steer-Fowler
Courses Plus Student 11,734 Points

Hi Paul,

Puts creates a new line and print continues on the same line.

When prompting for a name, it makes more sense to have it like this:

Name: Paul

than like this

Name:
Paul

In addition, gets creates a new line like puts does. You can use the method 'chomp' to remove this:

gets.chomp

Hope this helps