Python has bisect module: This module provides support for maintaining a list in sorted order without having to sort the list after each insertion http://python.active-venture.com/lib/module-bisect.html How to do this in Ruby?