From: Carlos Date: 2004-12-28T05:33:32+09:00 Subject: Re: split on '' (and another for split -1) ["trans. (T. Onoma)" , 2004-12-27 20.31 CET] > Here's a generic routine I'm working on: > > class String > def last=(str, separator=$/) > separator = '' unless separator > raise "separator must be a String" unless String === separator > s = self.split(separator, -1) > s[-1] = str > self.replace(s.join(separator)) > end > end > > $/ = "\n" > s = "ab\nc" > s.last = "123" > p s > # => "ab\n123" > > Now try: > > $/ = "" > s = "abc" > s.last = "123" > p s > > Unfortunately this does not give a congruent result. $/="" means paragraph mode, and it is acknowledged(?) by IO#gets, #readlines, String#each, #to_a, etc. Maybe you should do the same? And that solves your problems with split('') ;)))).