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 trialgreggv
Courses Plus Student 16,120 PointsWhy 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
Salman Akram
Courses Plus Student 40,065 PointsHi 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
greggv
Courses Plus Student 16,120 PointsThanks, would have been reading ruby docs from A - D (at least) before I'd found that.