Uploaded September 2022 | Updated September 2026, 2 weeks ago
Ruby offers a super convenient method for sorting complex objects in Enumerable#sort_by. But when sorting by multiple conditions or dealing with potential nil values, things get messy in a hurry.
This video shows off a common (but little-discussed) technique for building `sort_by` blocks that return prioritized arrays of values and then demonstrates how our new Put gem can accomplish the same thing with a cleaner and more expressive API that provides nil safety.
Check out the Put gem for yourself: github.com/testdouble/put
This video's example code lives here: github.com/testdouble/put_example
Read more about Put at our blog: blog.testdouble.com/talks/2022-09-28-a-better-way-to-sort-ruby-objects
CHAPTERS
00:00 – Introduction
02:10 – Using Enumerable#sort_by with multiple conditions
12:10 – How to use the Put gem
Ruby offers a super convenient method for sorting complex objects in Enumerable#sort_by. But when sorting by multiple conditions or dealing with potential nil values, things get messy in a hurry.
This video shows off a common (but little-discussed) technique for building `sort_by` blocks that return prioritized arrays of values and then demonstrates how our new Put gem can accomplish the same thing with a cleaner and more expressive API that provides nil safety.
Check out the Put gem for yourself: github.com/testdouble/put
This video's example code lives here: github.com/testdouble/put_example
Read more about Put at our blog: blog.testdouble.com/talks/2022-09-28-a-better-way-to-sort-ruby-objects
CHAPTERS
00:00 – Introduction
02:10 – Using Enumerable#sort_by with multiple conditions
12:10 – How to use the Put gem










