How to print something without a new line in ruby

前端 未结 3 1038
南笙
南笙 2021-02-04 23:07

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

相关标签:
3条回答
  • 2021-02-04 23:29

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

    0 讨论(0)
  • 2021-02-04 23:38

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

    0 讨论(0)
  • 2021-02-04 23:38
    $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?"

    0 讨论(0)
提交回复
热议问题