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

Why does the exclamation point gets its own line?

In the example at the end of this video (Input and Output | Ruby Basics) the exclamation mark (!) ends up on its own line. That looks very strange. Especially since it's clearly inside the string (between the quotes). What's going on?

2 Answers

Hi greggv,

Yeah I noticed that, he didn't explain more about "chomp" another string method that will remove newline character like "\n" in whitespace. We need to focus on "gets" function without chomp, it will push all the messages to the next lines which will often happen frequently.

Example:

puts β€œWhat is your name?”
name = gets
puts "Hello #{name}!!!!!!"
Hello Mike
!!!!!!

Let's consider to use chomp, see below

puts β€œWhat is your name?”
name = gets.chomp
puts "Hello #{name}!!!!!!"
Hello Mike!!!!!!

Prefer to read on Ruby Documentation - Chomp, Chop

Hope that helps. ;)

-Salman

Thanks, would have been reading ruby docs from A - D (at least) before I'd found that.