How can I clear the terminal in Ruby?

前端 未结 15 1713
心在旅途
心在旅途 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条回答
  •  生来不讨喜
    2020-11-30 07:04

    You can use system("clear") or system("cls") according to the terminal you are going to print.

    • If you are using the Windows Command Prompt, use system("cls").
    • If you are using a Mac or Linux system, just use system("clear").

    Or you can use a better way. Check this example.

    count = 0
    
    until count == 10
      system("cls") || system("clear")
      print count
      count += 1
      sleep 1
    end
    

提交回复
热议问题