On Feb 1, 11:30 pm, "Chris Shea" <cms... / gmail.com> wrote:
> On Feb 1, 9:20 pm, "Trans" <transf... / gmail.com> wrote:
> > untested but...
>
> >   i = [0..str.size / 2].index(' ')
> >   first_half, second_half = str[0...i], str[i..-1].strip
>
> > however, you might just prefer
>
> >   require 'facets/core/string/word_wrap'
> >   str.word_wrap(20)
>
> > T.
>
> 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).

To clarify...

  class String
    def halve
      i = size / 2
      j = i + self[i..-1].index(' ')
      return self[0...j].strip, self[j..-1].strip
    end
  end

T.