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 !

It is an interesting debate, but I suppose it's a bit of a moot point
now; it's too late to change these basic methods, even if we wanted
to.

On Dec 4, 2007 3:00 PM, MonkeeSage <MonkeeSage / gmail.com> wrote:
> On Dec 4, 1:31 pm, Christian von Kleist <cvonkle... / gmail.com> wrote:
> > On Dec 4, 2007 1:04 PM, Bill Kelly <bi... / cts.com> wrote:
> >
> >
> >
> >
> >
> > > From: "David A. Black" <dbl... / rubypal.com>
> >
> > > > [...] I just
> > > > think that Matz's abstraction of these as "dangerous", and dedication
> > > > of the ! to expressing that abstraction, is strikingly elegant and has
> > > > the weight of some kind of logic behind it. It hits a narrower target
> > > > -- it means that there's a whole class of tricky (or whatever) methods
> > > > that have to find some other way to express their trickiness -- but I
> > > > think it's worth it.
> >
> > > Ah.  I think I understand your viewpoint better now; thanks.
> >
> > > (And if nothing else, at least we can both agree on the "hits a
> > > narrower target" part.  <grin> )
> >
> > > Regards,
> >
> > > Bill
> >
> > Well, slice(-1) and slice!(-1) are equivalents for pop (non-modifying)
> > and pop! (modifying), right?
>
> Well...that's kind of cheating. Heh. ;) Semantically, they are very
> different; though pragmatically you get the same result. Kind of like
> a car hitting you at 50 k/mph gets the same result as you hitting a
> car at 50 k/mph, even though the car traveling 50 k/mph and yourself
> traveling 50 k/mph are very different. For perhaps a better
> analogy...these two do the same thing, even though they have very
> different semantics and implementations:
>
> p [1,2,3,4].last #=> 4
>
> arr   = [1,2,3,4]
> count = 0
> arr.each { | e |
>   if count == arr.size-1
>     p e
>   end
>   count += 1
> }
> # => 4
>
> The first is obviously the correct choice, even though you *can* do
> the second if you really wanted to.
>
> Regards,
> Jordan
>
>