Perish

博客园 首页 联系 订阅 管理

user = ARGV.first

prompt = '>'

 

puts "Hi #{user}, I'm the #{$0} script."

puts "I'd like to ask you a few questions."

puts "Do you like me #{user}?"

print prompt

likes = STDIN.gets.chomp()

 

puts "where do you live #{user}?"

print prompt

lives = STDIN.gets.chomp()

 

puts "what kind of computer do you have?"

print prompt

computer = STDIN.gets.chomp()

 

puts <<MESSAGE

Alright, so you said #{likes} about liking me.

You live in #{lives}. Not sure where that is.

And you have a #{computer} computer. Nice.

MESSAGE

我们用STDIN.gets取代了gets,这是因为如果有东西在ARGV里

标准的gets会把第一个参数当成档案而尝试从里面读取东西。如果是从使用者的输入(如stdin)中读取资料

的情况下我们必须明确的使用STDIN.gets

本文来自:http://lrthw.github.com/ex14/

posted on 2012-07-02 18:18  ---小青年---  阅读(533)  评论(0编辑  收藏  举报