One-line rescue, and beautiful sounds
I wanted to see if my WAV file wrapper would work in 1.9. I didn’t see any reason why it shouldn’t, but little things change here and there, so you never know.
Well, something did go wrong. I know this is sloppy, but I was getting the octave of notes from something like this:
note.match(/\\d+$/)[0] rescue 4
It turns out that NoMethodError is no longer a descendant of StandardError, and is thus no longer rescued by that rescue. So when the note didn’t have its octave in tow, note.match(/\d+$/) was returning nil, and nil doesn’t have a method [], but it would cruise right past the rescue clause.
A quick fix (a simple exercise left for the reader), and Ruby 1.9 is making me beautiful sounds:
Corey said,
October 15, 2007 @ 12:31 pm
This is how I would solve the exercise.
note =~ /\d+$/
$& || 4
Now it’s time to dance to your song.