Hola,
Objective-C has categories. They allow you to extend a class like this:
@interface NSArray (ArrayAdditions)
@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.
Hello Stefan,
Stefan Arentz wrote:
Hola,
Objective-C has categories. They allow you to extend a class like this:
@interface NSArray (ArrayAdditions)
@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
Laurent Sansonetti laurent@datarescue.be writes:
…
class Array
def randomize
# insert your code here
end
end
a = Array.new
a.randomize
Hmpf. That easy huh?
Thanks
S.
This is Ruby we’re talking about here. Nobody makes you crawl over broken
glass just to get things done.
Jason Creighton
···
On 18 Jun 2003 19:27:30 +0200 Stefan Arentz stefan.arentz@soze.com wrote:
Laurent Sansonetti laurent@datarescue.be writes:
…
class Array
def randomize
# insert your code here
end
end
a = Array.new
a.randomize
Hmpf. That easy huh?