"Michael Campbell" <michael_s_campbell / yahoo.com> schrieb im Newsbeitrag
news:20030626132342.22980.qmail / web12408.mail.yahoo.com...
> > In irb:
> >
> > >> '    A     50       3 for 130'.split(' ', 3)
> > => ["A", "50", "      3 for 130"]
> >
> > What I'd like Ruby to do
> >
> > >> '    A     50       3 for 130'.split(' ', 3)
> > => ["A", "50", "3 for 130"]
> >
>
>
> I'd agree, FWIW.  Ruby even appears internally inconsistent; why does
> it trim the leading \s off of 'A' and '50', but not the last element.
>  Just because it's the last one?  Bug?  Oversight?  By design?

I guess, it's because the last one receives the rest of whatever is there.
Personally I prefer to use regexps for splitting like this:

s.strip.split( /\s+/o, 3 )

Personally I think the behavior of split is quite complex and one has to
carefully read the documentation.  If you read that you'll find out that
splitting with a single space is a special case which leads exactly to
what you have observed.  At least doc and impl match. :-)

    robert