Created
February 7, 2013 18:53
-
-
Save danielmorrison/4733198 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# call as `ruby gets_is_wierd.rb some_nonexistant_file.txt` | |
filename = ARGV[0] | |
begin | |
File.open(filename) | |
rescue Errno::ENOENT => e | |
print "Rats. File not found. Try another: " | |
# gets fails here because IO acts on the last file, not STDIN. | |
# chagning it to STDIN.gets works. | |
# too much magic! | |
filename = gets.chomp | |
retry | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment