如何在没有新行的情况下在 ruby​​ 中打印某些内容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8723120/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 04:39:14  来源:igfitidea点击:

How to print something without a new line in ruby

ruby

提问by priya

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

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

回答by Sergio Tulentsev

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

使用print来代替。您可能希望通过STDOUT.flush.

回答by Rafael Diego Nicoletti

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

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