From: Chris Shea Date: 2007-02-02T14:30:06+09:00 Subject: Re: halving a string On Feb 1, 10:24 pm, "Chris Shea" wrote: > On Feb 1, 9:57 pm, "Bill Kelly" wrote: > > > From: "Chris Shea" > > > > Tested, and failed. The index returns the position of the very first > > > space. (Also, it would have to be str[0..(str.size / 2)].index(' ') > > > but, still, it's no good). > > > rindex() > > > :) > > > Regards, > > > Bill > > rindex, of course. Here's my current version then: > > class String > def halve > i = self[0..(length / 2)].rindex(' ') > if i.nil? > if include?(' ') > split(' ', 1) > else > [self, ''] > end > else > [self[0..i].strip, self[i..-1].strip] > end > end > end ahem: split(' ', 2)