Florian Gross
3/19/2005 5:48:00 PM
Glenn Parker wrote:
>> This is by design. The destructive forms of built-in methods usually
>> return nil when they do nothing.
>
> Yup, my bad. I know (really!) that this is by design, but I got myself
> confused while writing such a simple reply.
>
> For me, chaining methods is part of the Ruby way. Sacrificing the
> ability to easily chain method! calls was a mistake, IMHO. I still trip
> over this anomoly, and not once have I needed the functionality that
> took its place.
I tend to disagree as destructive methods are not supposed to be
chained. They are optimized forms when you would be doing a variable
assignment, IMHO.
So they are optimizations for this case:
a = a.strip
But not for this case:
puts a.strip
While you might argue that modifying a String can be faster than
constructing a new one based on the old one, I still think that that is
not what matz had in mind when adding them. I'm not sure if this truly
is how this feature was meant to be used so it's probably best to take
this with a grain of salt until matz has clarified the situation.