From: hfulton@... Date: 2001-07-13T00:44:29+09:00 Subject: [ruby-talk:17732] Re: Array#sort! returns nil when array empty > Array#sort! returns nil if the array is empty, whereas ri says it should > return itself: > arr.sort! -> arr This is one of those features that I consider questionable. The idea is that a bang-method which *doesn't* change its receiver will return nil to show that the receiver is unchanged. The same happens in a case like "Hello".gsub!(/foo/,"bar") -- this returns nil also (I haven't tried it today :) though). What makes the feature even more questionable in my mind is that in the case of sort!, it only returns nil for the pathological cases like an array of length 0 or 1. It doesn't check arrays of arbitrary size. So even the inconsistency is inconsistent. Personally, I wouldn't mind seeing this feature removed... it always bites me when I chain methods, resulting in an error that "nil" doesn't have any such method. And I personally never use this feature -- i.e., I never check to see whether the receiver was really modified. I just assume that my postcondition holds. For example, if I use gsub! to remove commas from a string, I don't care that it didn't have any commas to begin with. I just know that after the gsub!, it definitely has no commas. Hal