Skip to content

Instantly share code, notes, and snippets.

@danielmorrison
Created February 7, 2013 18:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielmorrison/4733198 to your computer and use it in GitHub Desktop.
Save danielmorrison/4733198 to your computer and use it in GitHub Desktop.
# 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