"explode" would be a better name. It's been called that in other languages.
-- Unknown
At least in PHP that is an alias for .split -- I'm not sure if we should use that name for something that returns the characters of a String as an Array...
-- Florian Gross
I wonder: does this work with various encodings? Is Oniguruma actually able to understand what a character is ? -- gabriele renzi
As far as I know the old regexp engine was already able to recognize UTF8 characters (but with no intelligent combination character and upper-to-lowercase handling) via the /u option. I think there's also options for misc. asian encodings.
So I would find it likely for Onigurama to also support it. :)
-- Florian Gross
string.chars.each seems much nicer than string.each_byte with conversions or string.split.
-- Olathe
I suggest using String#to_a instead, since this would be the inverse of Array#to_s.
-- Ken Kunz
I'm afraid I have to oppose. We have a free, unused method with String#to_a we could redefine instead of adding yet another method to the API.
While redefining String#to_a will cause some breakage, it's merely using Object#to_a, which is deprecated anyway. So, one way or another, breakage is going to occur.
- Dan
Wrong. String#to_a is Enumerable#to_a which returns all elements .each yields in an Array. This happens to be an array of lines in this case.
There has been talking about enhancing the .to_a interface with special boolean flags or named arguments, but I don't think this is the way to go.
I'd rather see different methods for different behavior.
-- Florian Gross
"explode" would be a better name. It's been called that in other languages.
-- Unknown
At least in PHP that is an alias for .split -- I'm not sure if we should use that name for something that returns the characters of a String as an Array...
-- Florian Gross
I wonder: does this work with various encodings? Is Oniguruma actually able to understand what a character is ? -- gabriele renzi
As far as I know the old regexp engine was already able to recognize UTF8 characters (but with no intelligent combination character and upper-to-lowercase handling) via the /u option. I think there's also options for misc. asian encodings.
So I would find it likely for Onigurama to also support it. :)
-- Florian Gross
string.chars.each seems much nicer than string.each_byte with conversions or string.split.
-- Olathe
I suggest using String#to_a instead, since this would be the inverse of Array#to_s.
-- Ken Kunz
I'm afraid I have to oppose. We have a free, unused method with String#to_a we could redefine instead of adding yet another method to the API.
While redefining String#to_a will cause some breakage, it's merely using Object#to_a, which is deprecated anyway. So, one way or another, breakage is going to occur.
- Dan
Wrong. String#to_a is Enumerable#to_a which returns all elements .each yields in an Array. This happens to be an array of lines in this case.
There has been talking about enhancing the .to_a interface with special boolean flags or named arguments, but I don't think this is the way to go.
I'd rather see different methods for different behavior.
-- Florian Gross