Ruby 读取输入

def prompt_and_get(prompt)
  print prompt
  res = readline.chomp  # readline是Kernel的一个方法
  throw :quit_requested if res == "!"
end

catch :quit_requested do
  name = prompt_and_get("Name:")
  age = prompt_and_get("Aage:")
  sex = prompt_and_get("Sex:")
end

你可能感兴趣的:(Ruby)