---
title: "Ruby 读取输入"
author: "keating"
date: "2009-09-15T14:10:41Z"
tags: []
categories: ["编程语言"]
slug: "ruby"
draft: false
lastmod: "2010-04-10T14:25:21Z"
id: 468995
url: "https://keating.iteye.com/blog/468995"
---

```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
```