Simon Strandgaard
12/7/2004 7:21:00 AM
On Tue, 7 Dec 2004 14:31:27 +0900, Yukihiro Matsumoto
<matz@ruby-lang.org> wrote:
> In message "Re: [rcr] String#split behaves odd"
> on Tue, 7 Dec 2004 14:16:06 +0900, "Peña, Botp" <botp@delmonte-phil.com> writes:
>
> |imho, I think he meant
> |
> |[] != [""]
> |
> |I myself thought that string#split would return an array of strings w a
> |minimum element of [""]
>
> I don't get it. [] is an array of strings with zero elements. ;-)
In the past I had the impression, that as long as there are no newline's
in the string, then split would always returns an array with one string.
"a".split(/\n/) #=> ["a"]
"a\nb".split(/\n/) #=> ["a", "b"]
However yesterday accidential the string I were about to split were empty,
and I had to add a specialcase (that only deals with the empty string).
I think many people don't have to make specialcases for the empty string,
if just split returns at least an array with one String element.
maybe title of this rcr should have been: change split result to
reduce specialcases.
--
Simon Strandgaard