What is the difference between gets
and gets.chomp
in Ruby?
I learned that Ruby gets reads user input and creates a new line, while gets.chomp
does the same but removes the newline character. Since gets
returns an object, you can call methods on it, like chomp
.
Does chomp
remove the newline after gets
creates it? And is the following order correct when calling gets.chomp
?
-
gets
prints a new line -
gets
returnstmp
-
tmp.chomp
removes the new line - User enters input
Can someone clarify how this works?