From: Han Holl Date: 2005-12-07T00:16:06+09:00 Subject: Re: Good Ruby Examples? ------=_Part_8662_17263991.1133882159467 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 12/6/05, Wayne Vucenic wrote: > > Hi Hampton, > > > My favorite is the well-known quicksort algorithm: > > def quicksort(a) > return a if a.size <=3D 1 > pivot =3D a[0] > quicksort(a.select {|i| i < pivot }) + > a.select {|i| i =3D=3D pivot } + > quicksort(a.select {|i| i > pivot }) > end > > quicksort is "hell" to write in C or C++ unless you're extremely clever. > > Wayne Vucenic > No Bugs Software > "Ruby and C++ Agile Contract Programming in Silicon Valley" > > And then demonstrate how this actually works with all kinds of objects that implement the comparison operators . Nice duck typing example. Han ------=_Part_8662_17263991.1133882159467--