Latest Tweet
- Dropped container of polynesian sauce on floor, fully-open side down. NOTHING CAME OUT. Chick-fil-A, champion of viscous sauces. 1 day ago
- More updates...
Categories
Tags
academia alcohol animals boyfriend cooking databases email forwards family Flickr food friends health Javascript Lexington Linux list Mario math movies music news OS X Perl 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
I guess I just prefer to see the dark side of things. The glass is always half empty. And cracked. And I just cut my lip on it. And chipped a tooth.
— Janeane Garofalo 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.