How to print something without a new line in ruby

Ruby

Ruby Problem Overview


puts statement in ruby automatically adds a new line, how do I avoid it?

Ruby Solutions


Solution 1 - Ruby

Use print instead. You may want to follow it up by STDOUT.flush.

Solution 2 - Ruby

Also, you'll need to append "\r" at end of line to indicate "carriage return" and do next print at beginning of current line

Solution 3 - Ruby

$stdout.sync = true

100.times do
    print "."
    sleep 1
end

"How can I use “puts” to the console without a line break in ruby on rails?"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionpriyaView Question on Stackoverflow
Solution 1 - RubySergio TulentsevView Answer on Stackoverflow
Solution 2 - RubyRafael Diego NicolettiView Answer on Stackoverflow
Solution 3 - RubyAtikaView Answer on Stackoverflow