How can I clear the terminal in Ruby?

前端 未结 15 1683
心在旅途
心在旅途 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:10

    This should cover windows and OSX/Linux terminals.

    def method_name
       puts "amit"
       if RUBY_PLATFORM =~ /win32|win64|\.NET|windows|cygwin|mingw32/i
          system('cls')
        else
          system('clear')
       end
    end
    method_name
    

提交回复
热议问题