After speaking at the Columbus Ruby Brigade last month on the topic of Ruby sorting, I’ve gotten a chance to use some of the sorting techniques I spoke about more over the last month at work. There were a few things I didn’t get a chance to cover since I was only giving a 5-10 minute lightning talk. There’s a few things I’ve come to understand a little better (benefits and gotcha’s) since then.
Things I talked about (feel free to check out the slides from my talk for examples of some of these things)
- Basic sorting with .sort and .sort!
- Sorting your own complex types by defining a <=> method on your class
- Sorting on the fly with blocks
- Sorting nested objects
Things I did not cover for various reasons. And blog posts covering them in more detail after the fact:
- Sorting a Hash – covering this topic didn’t seem as if it would add as much value as some of the other things I covered, so it got cut for the sake of time.
- When and specifically why to use sort_by – because I didn’t fully understand it just reading the rdoc on sort_by but now I do.
- Common mistakes when sorting using blocks – things I’ve learned along the way, in practice, since last month.