From: Laurent Sansonetti Date: 2003-06-19T00:16:25+09:00 Subject: Re: Categories like in Objective-C Hello Stefan, Stefan Arentz wrote: > Hola, > > Objective-C has categories. They allow you to extend a class like this: > > @interface NSArray (ArrayAdditions) > - (void) randomize; > @end > > @implementation NSArray (ArrayAdditions) > - (void) randomize { > ... this executes as if it is a method of NSArray ... > } > @end > > This example adds a randomize method to the existing NSArray class. > > The Category is active the moment it is loaded into the runtime. > > Is this also possible in Ruby? I know about Class.extend and Mixins, but what I > am looking for is the auto-loading. > > S. > > class Array def randomize # insert your code here end end a = Array.new a.randomize ;-) Hope that helps, -- Laurent