I just realized a minute ago why every time I
use the slice! method, one or two of my neurons
misfire.
All “bang” methods modify the receiver (though
the converse is not true – let’s not start
that one up again).
And most of them return that modified receiver…
but not the slice! method.
I see why this is, and I’m not complaining.
And of course, now that I know why it confuses
me, it never will again. Nice feeling!
Just for those who are keeping score, here’s
some Ruby-core trivia:
The String#slice! method works the same way
as Array#slice!, thank goodness (and Matz).
Offhand I don’t see any other bang methods
in the core that behave that way.
Some bang methods return nil if the object is
not actually changed: gsub!, delete!, others.
Now here’s a trivia question. What bang method
appears in two different core modules and (it
could be argued) does not really change its
receiver? (OK, in a way it does. Don’t quibble with
me.)
Just some midnight ramblings. Ignore at your leisure.
Some bang methods return nil if the object is
not actually changed: gsub!, delete!, others.
All but reverse!, sort!, and exit!
Now here’s a trivia question. What bang method
appears in two different core modules and (it
could be argued) does not really change its
receiver? (OK, in a way it does. Don’t quibble with
me.)
exit! does not modify anything. Its ! means “more dangerous” than non
bang version.
matz.
···
In message “Anyone ever confused by Array#slice! method?” on 03/03/27, “Hal E. Fulton” hal9000@hypermetrics.com writes:
I didn’t mean to induce you to reply to
this. But thanks.
Hal
···
----- Original Message -----
From: “Yukihiro Matsumoto” matz@ruby-lang.org
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Thursday, March 27, 2003 1:44 AM
Subject: Re: Anyone ever confused by Array#slice! method?
Some bang methods return nil if the object is
not actually changed: gsub!, delete!, others.
All but reverse!, sort!, and exit!
Now here’s a trivia question. What bang method
appears in two different core modules and (it
could be argued) does not really change its
receiver? (OK, in a way it does. Don’t quibble with
me.)
exit! does not modify anything. Its ! means “more dangerous” than non
bang version.