[bug] String#split wipes result

S

Simon Strandgaard

Another delicate problem.

irb(main):001:0> "abcde".split(/../)
=> ["", "", "e"]
irb(main):002:0> "abcde".split(/./)
=> []

Why is the second result empty?

I would have expected to see some empty strings.
 
T

ts

S> irb(main):002:0> "abcde".split(/./)
S> => []

S> Why is the second result empty?

svg% ri String#split
----------------------------------------------------------- String#split
str.split(pattern=$;, [limit]) => anArray
------------------------------------------------------------------------
[...]
If the _limit_ parameter is omitted, trailing null fields are
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^n¤
supressed. If _limit_ is a positive number, at most that number of
^^^^^^^^^
fields will be returned (if _limit_ is +1+, the entire string is
returned as the only entry in an array). If negative, there is no
limit to the number of fields returned, and trailing null fields
are not supressed.
[...]

svg%

you have only null fields in the result


Guy Decoux
 
S

Simon Strandgaard

ts said:
S> irb(main):002:0> "abcde".split(/./)
S> => []

S> Why is the second result empty?

svg% ri String#split
----------------------------------------------------------- String#split
str.split(pattern=$;, [limit]) => anArray
------------------------------------------------------------------------
[...]
If the _limit_ parameter is omitted, trailing null fields are
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^n¤
supressed. If _limit_ is a positive number, at most that number of
^^^^^^^^^ [snip]
you have only null fields in the result


Ahh.. I see. I just wondered what was going on.

I look at RI, but not carefully enough.

Thanks Guy.. I lost count of how many beers..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top