From: Tom Sawyer Date: 2002-07-09T06:43:49+09:00 Subject: Re: is there a better string.each? david, > str.split(//).each ... this involves excess overhead just to get each character. better to use: str.each_byte { |c| c.chr } but either way both of these take two steps when only one should be needed. str.each('') ... or $/ = '' str.each ... is much more elegent and can be implemented in such a way as to be more efficient. ~transami On Mon, 2002-07-08 at 14:55, David Alan Black wrote: > Hello -- > > 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. > > > David > > -- > David Alan Black > home: dblack@candle.superlink.net > work: blackdav@shu.edu > Web: http://pirate.shu.edu/~blackdav > > -- ~transami "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -- Benjamin Franklin