I never need the ending newline I get from gets
. Half of the time I forget to chomp
it and it is a pain in the....
Why is it there?
You need to use "\n" not '\n' in your gsub.
"\n" is newline, '\n\ is literally backslash and n.
\r\n should probably do the trick.
When a line break occurs at the end of a block of text, it is called a trailing newline. The newline character is important in computer programming, since it allows programmers to search for line breaks in text files.
Like puts
(which sounds similar), it is designed to work with lines, using the \n
character.
gets
takes an optional argument that is used for "splitting" the input (or "just reading till it arrives). It defaults to the special global variable $/
, which contains a \n
by default.
gets
is a pretty generic method for readings streams and includes this separator. If it would not do it, parts of the stream content would be lost.
var = gets.chomp
This puts it all on one line for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With