Re: How to write *include* like Ruby?
Steve Dekorte <[email protected]> Sat, 19 May 2012 14:13:55 -0700
| Newsgroups | gmane.comp.lang.io |
|---|---|
| Message-ID | <[email protected]> |
Hi lijie, lijie wrote: > I want to write Io code like Ruby meta programming. *Module#include* is an important method to extend classes. It depends on how you want lookups and updates to work with your traits. 1. Traits not overriding object slots and updates to occur on the object: Object appendNonOverridingTrait := method(aTrait, self addProto(aTrait) return self ) 2. Traits overriding object slots and updates to occur on the object: Object insertOverridingTrait := method(aTrait, traitInstance := aTrait clone setProto(self proto) self setProto(traitInstance) return self ) With delegation (via overriding the forward method) you could implement: 3. Traits not overriding object slots and updates to occur on the trait 4. Traits overriding object slots and updates to occur on the trait These methods would require maybe 10 lines of code each. I can post implementations if that is the behavior you need. Cheers, Steve