This post originated from an RSS feed registered with Ruby Buzz
by Daniel Berger.
Original Post: Ignoring errors
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
If you want to create a directory in Ruby you do this:
Dir.mkdir("foo")
What if "foo" already exists? An error occurs. You could resort to this:
Dir.mkdir("foo") unless File.exists?("foo")
That's rather longwinded. Since 99.9% of the time the only reason for Dir.mkdir to fail is that the directory already exists wouldn't it be nice to just ignore this error? Yup: