I was looking for the Ruby equivalent to getattr and I ran into this article:
http://stackoverflow.com/questions/786412/what-is-the-ruby-equivalent-of-pythons-getattr
The answer was not generic enough for me. I'd like to implement a Ruby equivalent to Python's built-in sorted function.
So after a little more searching, I found the answer: send and posted it.
Thursday, July 2, 2009
Subscribe to:
Post Comments (Atom)
1 comment:
Hey Mark!
If you're looking at doing sorting, check out the spaceship operator: <=>
It lets you do stuff like:
address_book.sort {|a,b| a.last_name.downcase <=> b.last_name.downcase}
Post a Comment