How can I clear the terminal in Ruby?

前端 未结 15 1687
心在旅途
心在旅途 2020-11-30 06:14

I would like to know to how to do in Ruby what I can do with system(\"clear\") in C. I wrote a program like

puts \"amit\"
system(\"clear\")
         


        
15条回答
  •  萌比男神i
    2020-11-30 06:56

    clear_screen (Ruby 2.7+)

    Starting from Ruby 2.7, there is a build-in and cross-platform way to clear the terminal output:

    require 'io/console'
    
    $stdout.clear_screen # or STDOUT.clear_screen
    

    See the difference between $stdout and STDOUT here.

提交回复
热议问题