From: Robert Klemme Date: 2008-03-11T19:12:19+09:00 Subject: Re: Ordered Collection 2008/3/11, Peter Hug : > If class X has a method <=>(aX), I can sort an Array containing > instances of X using Array.sort!. > > What I really would like is an array that is always ordered. IOW, I want > the object to be inserted at the correct location inside the array when > the object is added to the array. > > Is there an efficient way to do this? Yes. You can either use binary search on the Array to insert or you use a Tree. Both can be found in RAA: http://raa.ruby-lang.org/project/ruby-bsearch/ http://raa.ruby-lang.org/project/ruby-rbtree/ Kind regards robert -- use.inject do |as, often| as.you_can - without end