得到一个输入的 char
与 gets.chomp 不同,这不会等待新行。
必须包含 stdlib 的第一部分
require 'io/console'
然后可以编写一个辅助方法:
def get_char
  input = STDIN.getch
  control_c_code = "\u0003"
  exit(1) if input == control_c_code
  input
end
如果按下 control+c,它就会退出。
与 gets.chomp 不同,这不会等待新行。
必须包含 stdlib 的第一部分
require 'io/console'
然后可以编写一个辅助方法:
def get_char
  input = STDIN.getch
  control_c_code = "\u0003"
  exit(1) if input == control_c_code
  input
end
如果按下 control+c,它就会退出。