From: "trans. (T. Onoma)" Date: 2004-12-28T06:25:15+09:00 Subject: Re: split on '' (and another for split -1) On Monday 27 December 2004 03:33 pm, Carlos wrote: | ["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('') ;)))). Boy, that's a real side-splitter! Watch me slap my knee! ;)))). But seriously, you can call it anything you wish. It does not change the behavior. "Moreover you have a peculiar definition of paragraph. ".split('') => ["M", "o", "r", "e", "o", "v", "e", "r", " ", "y", "o", "u", " ", "h", "a", "v", "e", " ", "a", " ", "p", "e", "c", "u", "l", "i", "a", "r", " ", "d", "e", "f", "i", "n", "i", "t", "i", "o", "n", " ", "o", "f", " ", "p", "a", "r", "a", "g", "r", "a", "p", "h", ".", " "] A more informative explanation of this "paragraph mode" might actually be helpful. T.