summaryrefslogtreecommitdiff
path: root/examples/trapping_eof.rb
diff options
context:
space:
mode:
authorGregory Brown <gregory.t.brown@gmail.com>2009-02-02 11:59:04 -0500
committerGregory Brown <gregory.t.brown@gmail.com>2009-02-02 11:59:04 -0500
commit6ff9ffe5fabf766183db9ed1d548b70e21f02eb6 (patch)
tree19a69d22f4c15a7ec1dfb69988f2fa51365b08fe /examples/trapping_eof.rb
parent37cd9cff1783911ab51afd90ba6588ce12c58b57 (diff)
downloadhighline-6ff9ffe5fabf766183db9ed1d548b70e21f02eb6.tar.gz
restructuring
Diffstat (limited to 'examples/trapping_eof.rb')
-rw-r--r--examples/trapping_eof.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/examples/trapping_eof.rb b/examples/trapping_eof.rb
new file mode 100644
index 0000000..6646a80
--- /dev/null
+++ b/examples/trapping_eof.rb
@@ -0,0 +1,22 @@
+#!/usr/local/bin/ruby -w
+
+# trapping_eof.rb
+#
+# Created by James Edward Gray II on 2006-02-20.
+# Copyright 2006 Gray Productions. All rights reserved.
+
+require "rubygems"
+require "highline/import"
+
+loop do
+ begin
+ name = ask("What's your name?")
+ break if name == "exit"
+ puts "Hello, #{name}!"
+ rescue EOFError # HighLine throws this if @input.eof?
+ break
+ end
+end
+
+puts "Goodbye, dear friend."
+exit