From: Robert Klemme Date: 2006-03-21T18:33:50+09:00 Subject: Re: iterate chars in a string 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 > ==> > 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' => true irb(main):004:0> "foo\nbar".to_enum(:each_byte).each {|c| puts c.chr} f o o b a r => "foo\nbar" irb(main):005:0> "foo\nbar".to_enum(:scan, /./m).each {|c| puts c} f o o b a r => "foo\nbar" Cheers robert