From: "Brian Schröder" Date: 2005-10-20T04:11:28+09:00 Subject: Re: On 19/10/05, Xeno Campanoli wrote: > #!/usr/bin/ruby > # > # try003.rb > # > # Here is my bug. It turns out it's not as whacky as I though. It just > # was failing because Ruby cannot sort booleans; presumably an omission: > > b = [false,true,false,true] > > # Sorry about this omission the first time: Version was ruby 1.8.1 on CentOS > # Linux. > b.sort.each do |bool| > p bool > end > > What is bigger, a true or a false? One might argue that the truth is the biggest thing, on the other hand its nearly always the case that a lie needs much more effort than the truth. So what to do? false < true or true < false or true == false? Now to help you irb(main):002:0> def false.<=>(o) o ? -1 : 0 end => nil irb(main):003:0> def true.<=>(o) !o ? 1 : 0 end => nil irb(main):004:0> [true, false, true, false, false].sort => [false, false, false, true, true] regards, Brian -- http://ruby.brian-schroeder.de/ Stringed instrument chords: http://chordlist.brian-schroeder.de/