Latest Tweet
- Remember folks: the blue mini neon sour gummi worms are best. 2 weeks ago
- More updates...
Categories
Tags
academia alcohol animals boyfriend cooking databases email forwards family Flickr food friends health Lexington Linux list Mario math movies music news OS X Perl photos PHP politics programming quizzes Rails rants reading Ruby screenshots shopping Sims sports themes tutorials Twilight is ridiculous vehicles video games videos weather Web development work zombies again-
Recent Comments
-
Random Quote
The reason the grass is always greener on the other side is that, you're so busy looking at their grass, you forget to water your own.
— unknown Syndication
All posts RSS feed
sortable arrays of symbols in Ruby
I got this error in my Rails app because I was trying to sort an array of symbols: undefined method `<=>' for :my_symbol:Symbol. I defined the spaceship method for the Symbol class and included the Comparable module in order to have other comparison methods available for symbols.
Ruby
include Comparable
def <=>(other)
self.to_s <=> other.to_s
end
end
This lets me do things like the following:
Cross-posted to my DZone Snippets page.