From: Hugh Sasse Date: 2010-03-04T21:34:30+09:00 Subject: [ruby-core:28470] Re: [Bug #2647] Lack of testing for String#split On Thu, 4 Mar 2010, Dawid Grzesiak wrote: > Issue #2647 has been updated by Dawid Grzesiak. > > > Or in this example: > > irb(main):053:0> "..l..".split "." > => ["", "", "l"] > > there is no symmetry :/ hgs@Q2P14HGS ~ 12:27:13$ ruby -e 'puts "..l..".split(/\./).inspect' ["", "", "l"] # Confirmed for regexps hgs@Q2P14HGS ~ 12:27:36$ ruby -e 'puts "..l..".split(/\./,-1).inspect' ["", "", "l", "", ""] # Limit parameter solves this hgs@Q2P14HGS ~ 12:27:46$ ri String#split gives: ----------------------------------------------------------- String#split str.split(pattern=$;, [limit]) => anArray From Ruby 1.8 ----------------------------------------------------------------- ------- [...] If the _limit_ parameter is omitted, trailing null fields are suppressed. 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 suppressed. HTH Hugh