In my application I need to show a list of songs. Right now I'm doing this:
Song.all.sort {|x,y| x.artist.name <=> y.artist.name }
Unfortunately, this means that "The Notorious B.I.G" will sort with the T's while I want him to sort with the N's (i.e., I want to ignore articles -- "the", "a", and "an" -- for the purposes of sorting.
My first thought was to do this:
Song.all.sort {|x,y| x.artist.name.gsub(/^(the|a|an) /i, '') <=> y.artist.name.gsub(/^(the|a|an) /i, '') }
But it doesn't seem to work. Thoughts?