From: Robert Dober Date: 2006-03-21T18:47:49+09:00 Subject: Re: iterate chars in a string ------=_Part_13539_24200378.1142934451654 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Sorry Robert but I do not think I made myself too clear we now about each_byte and I already combined your #chr and String#each_byt= e so we had already established "Ty Mr. Klemme".each_byte { |b| puts b.chr } which is pretty elegant, don't you agree? So Enumerators are not needed. Now after that we switched discussing the behaviour of String#each and I *really* feal that String#each should us give that kind of behaviour. As I see that a lot of people think that the current behaviour of String#each is a good one, and changing it would not be an option anyway I thaught that the only solution would be to enhance the behaviour of String#each. The idea for that behaviour comes from Ruby itself (look at IO#gets) then "Ty Mr. Klemme".each_byte { |b| puts b.chr } would be the same as "Ty Mr. Klemme".each( 1 ) { |b| puts b } There is always more than one way to do it ;) Robert On 3/21/06, Robert Klemme wrote: > > Robert Dober wrote: > > Please don't top post. > > > 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 have that already: it's Enumerator. > > irb(main):003:0> require 'enumerator' > =3D> true > irb(main):004:0> "foo\nbar".to_enum(:each_byte).each {|c| puts c.chr} > f > o > o > > b > a > r > =3D> "foo\nbar" > irb(main):005:0> "foo\nbar".to_enum(:scan, /./m).each {|c| puts c} > f > o > o > > b > a > r > =3D> "foo\nbar" > > Cheers > > 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_13539_24200378.1142934451654--