From: Dossy Date: 2002-07-06T02:13:48+09:00 Subject: Re: is there a better string.each? On 2002.07.06, Dave Thomas wrote: > Tom Sawyer writes: > > > thought it was strange myself. personally i'd like it if String and > > Array where a little more in harmony. in c/c++ strings are arrays, arn't > > they? > > Perhaps it might be better to say that (currently) the implementation > of Strings is reminiscent of Arrays. However, I'm not sure that this > is a fundamental property of strings, so saying that "strings are > arrays" might be too strong. > > Having said that, I'd personally prefer > > str.each - returns the characters of str as strings > > str.each_byte - returns the characters/bytes of str > (depending on Ruby version) > > str.each_line - like the current str#each > > But the change to #each would probably break a lot of code... I'm definitely all for this. This way, when m17n gets implemented in Ruby, String#each can return one (or more) bytes, depending on the appropriate number of bytes for the representation of the character in the locale's encoding. String#each_byte literally returns each byte regardless of locale or encoding, and String#each_line does what String#each does today. Is it worth breaking a lot of code to preserve POLS here, though? Perhaps Ruby 2.x can break backwards compatibility -- usually it's accepted practice to break backward compatibility in a major version change. -- Dossy -- Dossy Shiobara mail: dossy@panoptic.com Panoptic Computer Network web: http://www.panoptic.com/ "He realized the fastest way to change is to laugh at your own folly -- then you can let go and quickly move on." (p. 70)