From: Austin Ziegler Date: 2002-07-09T06:38:19+09:00 Subject: Re: is there a better string.each? On Tue, 9 Jul 2002 05:55:28 +0900, David Alan Black wrote: > On Mon, 8 Jul 2002, Austin Ziegler wrote: >> If $/ (the argument to String#each) could be made to accept >> regex, then the record separator could be String#each(//) if >> necessary, allowing character-by-character parsing. This is not >> currently possible. > I'll put in (yet another :-) plug for String#split: > > str.split(//).each ... > > I think the idea of having String#each take a regex is, > essentially, a kind of compression of this -- in other words, > instead of #split'ing on a regex and then iterating through the > resulting array, moving the regex intelligence into the argument > to #each. I'm of two minds about the merits of this, but in any > case I don't think there would be anything possible in the > language that isn't possible now. I agree. However, even though the code may be different, that's basically what String#each is doing *already*, except that it's by a string. foo.each(bar) ... *could* be implemented as foo.split(/#{bar}/).each ... very easily, with the one difference that if bar.empty?, then it's treated as: foo.split(/\n+/m)).each ... I think what I'm getting at is that String#each already does the equivalent of String#split#each -- but does so in a way that is less useful than String#split#each (IMO). Why not make String#each act like String#split#each? -austin -- Austin Ziegler, austin@halostatue.ca on 2002.07.08 at 17.33.30