From: dblack@... Date: 2007-08-14T23:38:30+09:00 Subject: Re: Does an Array#apply make any sense at all? On Tue, 14 Aug 2007, nikolai.weibull@gmail.com wrote: > On Aug 14, 2:07 pm, dbl...@rubypal.com wrote: >> Hi -- >> >> >> >> On Tue, 14 Aug 2007, Robert Klemme wrote: >> >>> Your method should be called "apply!" because it's destructive. >> >> I could be wrong, but I think the convention (at least in core Ruby) >> is that ! methods always come in a pair with the non-! version. I >> don't think there are any cases where there's just a method called m! >> where the ! indicates destructiveness (or other "danger"). All the >> unpaired destructive methods have non-! names. > > Ugh. This was so NOT about whether to call the method Array#apply or > Array#apply!. I know -- I was just replying to a tangential point that Robert raised. > I just wrote the absolute shortest solution I could > think of. I didn't suggest that it was the final version. Yes, > seeing as how my definition mutates its target, Array#apply! is the > appropriate name. I would still disagree, on the grounds that ! doesn't mean that a method changes its receiver; it means the method is "dangerous" (Matz's definition), and that only has meaning in reference to a non-dangerous but otherwise equivalent method. > I simply didn't want to clutter the definition > thusly: > > class Array > def apply(method) > first.send(method, *self[1..-1]) > end > end > > (which sort of begs the question why we don't have Array#rest ;-) Good question :-) David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)