Hi --

On Wed, 5 Dec 2007, Christian von Kleist wrote:

> Good point.  :)
>
> I remember having the same question about shift/unshift when I first
> learned Ruby.  I remember doing something like the following:
>
> item = items.shift!
>
> ...and I was surprised to see a NoMethodError.  It seemed to violate
> the rule I supposed existed: all destructive methods end in !

We're lucky that there's no such rule. Imagine:

   "string" <<! "more text"
   array.clear!
   obj.instance_variable_set!
   (etc.)

:-)

The use of destructive-sounding names (or, where appropriate,
non-destructive-sounding ones plus the "danger" flag) works out well.
The only somewhat anomalous case I know of is delete(!), where
String#delete is not destructive but Array#delete is. I'm not sure why
those differ from each other in that respect.


David

-- 
Upcoming training by David A. Black/Ruby Power and Light, LLC:
    * Intro to Rails, London, UK, December 3-6 (by Skills Matter)
See http://www.rubypal.com for details and 2008 announcements!