Beyond Enumerable: Heaps and Priority Queues | baweaver

12-Jun-2026 9
Our last post named windows: moving through a collection while maintaining running state. This one goes after a different shape, one that shows up the moment a collection won’t sit still long enough for sort_by to help. Enumerable gives you min_by, max_by, sort_by, and they’re enough when the collection is static. You ask once, they walk everything, and you get your answer, but they keep nothing between calls. Ask again after an insert or a delete and they redo all that work from scratch. On a collection that changes on every read, you’re re-scanning every time, and if you never had an algorithms class that told you there’s a name for the structure that fixes this, you end up rebuilding it by hand without knowing what you’re building. I did that for years. These articles exist so the path is shorter for other people.
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle