From: Mark Hubbart Date: 2004-07-15T02:21:07+09:00 Subject: Re: String.split On Jul 14, 2004, at 2:51 AM, Lloyd Zusman wrote: > Mark Hubbart writes: > >> On Jul 13, 2004, at 9:03 PM, Bill Kelly wrote: >>> >>> [ ... ] >>> >>> /(?>> >>> ...Maybe there's another way to do it... If anybody knows >>> I'd like to learn... >> >> as of now, this works: >> >> irb(main):001:0> " spaces of doom ".split(nil) >> => ["spaces", "of", "doom"] >> >> Why shouldn't nil be the only special case? If the $variable is set to >> nil, it uses this kind of split anyway. >> >> And it's no more characters to type than " " ;) >> >> Mark > > ... and the following has even fewer characters to type: > > irb(main):001:0> " spaces of doom ".split() > => ["spaces", "of", "doom"] ... which is the same as: irb(main):001:0> " spaces of doom ".split => ["spaces", "of", "doom"] However, I was mistakenly thinking that #split(nil) would be exactly the same as #split(" ")... but it isn't. I tried setting $; to "." and it no longer worked. It seems that it should, though: when you want the default behavior of #split, you set $; to nil. it seems rather logical that #split(nil) should split using that default behavior. Oh well :) cheers, Mark