puts
statement in ruby automatically adds a new line, how do I avoid it?
Puts automatically adds a new line at the end of your message every time you use it. If you don't want a newline, then use print .
We can also use "\n" ( newline character ) to print a new line whenever we want as used in most of the programming languages.
While the print method allows you to print information in the same line even multiple times, the puts method adds a new line at the end of the object. On the other hand, p is useful when you are trying to understand what your code does, e.g. when you are trying to figure out a certain error.
\r\n should probably do the trick.
Use print
instead. You may want to follow it up by STDOUT.flush
.
Also, you'll need to append "\r" at end of line to indicate "carriage return" and do next print at beginning of current line
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