From: Mauricio Fernandez Date: 2006-03-21T18:25:29+09:00 Subject: Re: iterate chars in a string On Tue, Mar 21, 2006 at 05:58:50PM +0900, 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. Besides, RUBY_VERSION # => "1.8.4" require 'enumerator' def foo(x) x.each{|y| p y.chr} end str = "foo bar baz" foo(str.enum_for(:each_byte)) # >> "f" # >> "o" # >> "o" # >> " " # >> "b" # >> "a" # >> "r" # >> " " # >> "b" # >> "a" # >> "z" -- Mauricio Fernandez - http://eigenclass.org - singular Ruby