From: Robert Dober Date: 2006-03-21T18:09:03+09:00 Subject: Re: iterate chars in a string ------=_Part_13195_746032.1142932127107 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Would it not be nice to simply extend the behavior of String#each e.g. like this "Really nothing intelligent to tell".each do |c| puts c end =3D=3D> R e etc. etc. might be 1 (imagine what n could do!) [ we could even formulate endless loops like this "".each 0 do puts "Eternity is a hack of a long time" end that is *really* great ;) ] or shall everybody do it oneself class String def my_iterator .... I just do not think so. Cheers Robert On 3/21/06, Robert Klemme wrote: > > jogloran wrote: > > The thing I don't like about this behaviour is that an algorithm which > > operates on containers and expects #each can't work immediately with > > strings. > > That's not true. It just depends on what you consider to be the parts > of a string. I'd agree that naturally one would expect characters to be > that - but "lines" is another option. And that's the one that has been > chose by Matz. It has some advantages, too, e.g. if you slurp in a file > into a single string and then want to iterate the lines. > > Kind 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_13195_746032.1142932127107--