From: "juan pedro meriƱo" Date: 2007-06-29T01:29:48+09:00 Subject: Re: Array Problem, sort Array ------=_Part_59023_25590702.1183048190783 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline When i found a shoppyng under ruby? 2007/6/28, dblack@wobblini.net : > > Hi -- > > On Thu, 28 Jun 2007, Pe=F1a, Botp wrote: > > > # > A little digression for everyone though... > > # > irb(main):013:0> [nil].sort > > # > =3D> [nil] > > # > > > # > is that intended? > > # > > # Well, you don't need the comparison operator where there's only one > > # element, do you ? > > > > careful with the "one" there. The array returned may be complex. > > eg, > > irb(main):029:0> [[nil,[nil,"a"]]].sort > > =3D> [[nil, [nil, "a"]]] > > irb(main):030:0> [[nil,[nil,"a"]]].flatten.sort > > NoMethodError: undefined method `<=3D>' for nil:NilClass > > from (irb):30:in `sort' > > > > again, as i've said to Phrogz, the behavior hints that nil elements by > themselves are sortable. Remember, programs contain blackboxes wc may be > complex and not obvious, eg > > complex_proc_ret_array.sort_complex.foo_proc.bar_proc > > > > one could argue bluntly too, eg > > [nil].sort > > =3D>[nil] # yes, there is no need to sort > > [nil,nil].sort > > =3D>[nil,nil] # yes, there is no need to sort > > > > I really value consistency of object behavior when it comes to ruby, > maybe because it's too dynamic and i want least number of surprises > (especially when you chain things). > > What about: > > class C; end > [C.new].sort > > ? > > > David > > -- > * Books: > RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) > RUBY FOR RAILS (http://www.manning.com/black) > * Ruby/Rails training > & consulting: Ruby Power and Light, LLC (http://www.rubypal.com) > --=20 Juan Pedro Meri=F1o Diaz Ing de Sistema CURN ------=_Part_59023_25590702.1183048190783--