From: Gregory Seidman Date: 2006-03-21T21:28:14+09:00 Subject: Re: iterate chars in a string On Tue, Mar 21, 2006 at 04:31:39PM +0900, 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. A decision had to be made on how to split up a string when using each. The decision was made to split it up by lines, since that was deemed to be the most often used case. I think that's probably a correct assessment. Now, if you want it to use something other than newlines as its split, you can explicitly split by whatever you want: 'foobar'.split('').each { |c| puts c } Basically, stringvar.each is a shortcut for stringvar.split("\n").each because line splitting is the common case. } Daniel Tse --Greg } On 3/21/06, Robert Dober wrote: } > } > Mike I really agree, I *was* expecting that behavior from "each" too, some } > time ago, and it took me some time to figure it out } > BTW I think the "nicest" solutions is mine combined with Robert's (pun } > intended) } > } > "Ty Mr. Klemme".each_byte { |b| puts b.chr } } > } > my "%" stuff was rather clumsy. } > } > bye for now } > Robert } > } > On 3/20/06, Berger, Daniel wrote: } > > } > > > -----Original Message----- } > > > From: Mike Austin [mailto:noone@nowhere.com] } > > > Sent: Monday, March 20, 2006 12:39 PM } > > > To: ruby-talk ML } > > > Subject: Re: iterate chars in a string } > > > } > > > } > > > "I am puzzled".each_byte { |b| puts b.chr } } > > > } > > > I'm surprised that not many people knew about 'each_byte()'. } > > > Maybe it's a } > > > problem with Ruby docs? Or maybe it is just } > > > counter-intuitive - I would expect } > > > each() iterate over bytes, and provide each_lines() to } > > > iterate over lines instead. } > > > } > > > Mike } > > > } > > > http://www.rubycentral.com/ref/ } > > } > > Modifying String#to_a to return an array of characters has been brought } > > up before (ruby-talk:148588 and following). I don't think Matz likes } > > the idea, though. } > > } > > Dan } > > } > > } > } > } > -- } > Deux choses sont infinies : l'univers et la b?tise humaine ; en ce qui } > concerne l'univers, je n'en ai pas acquis la certitude absolue. } > } > - Albert Einstein } > } >