如何确保我的ruby命令行程序清除屏幕,而不管它是在windows、macosx还是基于linux的发行版上?
如果我在windows上,命令如下:

system('cls')

而在Mac上的Linux上则是这样:
system('clear')

最佳答案

def clear_screen
  puts "Going to clear the screen"
  if RUBY_PLATFORM =~ /win32|win64|\.NET|windows|cygwin|mingw32/i
    system('cls')
  else
    system('clear')
  end
end

关于ruby - 跨平台Ruby方法清除终端屏幕,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43731221/

10-14 14:27