From: Robert Dober Date: 2006-03-29T17:09:06+09:00 Subject: Re: Range#to_a, each - why inconsistent? ------=_Part_654_4189267.1143619743658 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 3/29/06, vsv wrote: > > Could someone explain me, please, why Range with one element is > iterated inconsistently when this element is empty string: > > $ irb --simple-prompt > >> ('a'..'a').to_a > =3D> ["a"] > >> (1..1).to_a > =3D> [1] > ## but: > >> ("".."").to_a > =3D> [] > >> ("".."").each{|s| puts 'Inside'} > =3D> "".."" > Why to_a returns empty [] and each block never executed? > Is it bug or feature? > Any reasonable explanation? > > thanks > Sergey > > > Sergey this looks like a bug to me as far as I recall the definition of a range, "" is part of the range ("".."") I verified with irb and ("".."") =3D=3D=3D "" returns true "" <=3D> "" returns 0 as expected, "".succ =3D> "" which is not quite conclusive for me, but see below anyway it seems inconsistent that ("".."").to_a.include?("") returns false while ("".."") =3D=3D=3D "" returns true No I have mimicked the bahvior with class NilClass def succ; nil; end def <=3D>(other); 0; end end Guess what (nil..nil).to_a returns ?? [nil] as expected the behavior you described clearly seems to be a bug. Regards Robert -- Deux choses sont infinies : l'univers et la b=EAtise humaine ; en ce qui concerne l'univers, je n'en ai pas acquis la certitude absolue. - Albert Einstein ------=_Part_654_4189267.1143619743658--