Jordi Bunster wrote:
> On Oct 31, 2009, at 12:44 PM, Robert Gleeson wrote:
> 
>> Yup, you can write your own mutating methods that mutate the
>> receiver(like chomp!, gsub!, sub!, and so on), but you can't mutate  
>> any
>> of the core classes because you cannot reassign self.
> 
> Some core classes know how to replace themselves:
> 
> class String
>    def clobber!
>      replace ''
>    end
> end
> 
> I wonder why Object (or BasicObject) doesn't know this trick.
> 
> I also wonder why "replace" isn't called "replace!" :)

This is cool, but it only works for mutating methods that already exist, 
if you want to write your own you're out of luck, as far as the core 
classes go.
-- 
Posted via http://www.ruby-forum.com/.