简体   繁体   中英

How to print something without a new line in ruby

在ruby中的puts语句自动添加一个新行,我该如何避免呢?

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

此外,您需要在行尾添加“\\ r”以指示“回车”并在当前行的开头执行下一次打印

$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?"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM