Thursday, July 2, 2009

Ruby equivalent to Python's getattr

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.

1 comment:

brad said...

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}