From: Robert Dober Date: 2007-07-24T05:38:43+09:00 Subject: Re: Is there a replacement for sub? On 7/23/07, bbiker wrote: > My primary objection to have a nil return is that it prevents me from > safely chaining bang! methods. > > The nil return is counter-intuitive and violates the Principle of > Least Surprise Yours yes, mine not at all ... unless gsub!(..., ...) is quite useful to me. > > As I said before given an array such as arr = [1, 2, 3, 4, 5, 6], I > can do > > new_arr = arr.flatten.uniq.sort => [1, 2, 3, 4, 5, 6] > > Intuitively I would think that I should be able to do > arr.flatten!.uniq!.sort!; however because of the nil return by > #flatten!, a NoMethodError is raised by #uniq! since the nil object > does not have a uniq! method. That is a different case, I adhere to your POV on this one. > > Note that not all bang! methods return nil when nothing was changed in > the receiver. Array#sort! return self if self was already sorted. > > Hopefully Matz might be reading this thread and might consider > changing the behavior of bang! methods returns. Why should he? He *might* consider it if it were a largely discussed and backed up RCR, there seems some way to go... > > > Robert -- We're on a mission from God. ~ Elwood,