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

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.