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

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


You need to use print instead of puts. Also, if you want the dots to appear smoothly, you need to flush the stdout buffer after each print...

def print_and_flush(str)  print str  $stdout.flushend100.times do  print_and_flush "."  sleep 1end

Edit: I was just looking into the reasoning behind flush to answer @rubyprince's comment, and realised this could be cleaned up a little by simply using $stdout.sync = true...

$stdout.sync = true100.times do  print "."  sleep 1end