$futures = ({})
puts "Type `hello' to get your number, just like at the post office."
puts "Except you say `hello' instead of pressing a button."
puts "--------------------------------------------------------------"
def get_an_id
$futures.size
end
while true
print "Yes? "
line = gets
if line == "hello\n"
id = get_an_id
puts "OK, I'll be calling you #{id}. I want your name."
puts "When you're ready, give it to me by typing `#{id}: John Doe'."
$futures[id] = proc { |name|
puts "Thanks, #{id}."
puts "Now, I'd like your address, too. Give it to me in the same way."
$futures[id] = proc { |address|
puts "Thanks again, #{id}."
puts "I'll be sending a hitman to #{name} at #{address}."
$futures[id] = proc {
puts "I'm done with you. Get out of here."
}
}
}
elsif line =~ /^(.*?): (.*)$/
id = $1.to_i
response = $2
if $futures.has_key? id
$futures[id].call response
else
puts "Huh? Say hello first."
end
else
puts "Eh?"
end
end