Re: How to write *include* like Ruby?

Jeremy Tregunna <[email protected]> Sat, 19 May 2012 14:24:28 -0600
Newsgroups gmane.comp.lang.io
Message-ID <[email protected]>
Additionally, Io's traits copy slots they don't work like Ruby mixing. Ruby mixing create a new object and place it between your object and its parent (manipulating the inheritance graph). This is really bad from a language standpoint as it adds additional overhead for each and every mixing you include via increasing the complexity of finding superclass methods for instance (more work lookup has to do).

Regards,

Jeremy Tregunna


On Saturday, 19 May, 2012 at 8:48 AM, lijie wrote:

>    
> Hi,
>  
> I want to write Io code like Ruby meta programming. *Module#include* is an important method to extend classes.
>  
> In Io, I wrote some code:
>  
> > include := method (module,
> >   call sender addTrait(module)
> > )
> >  
> > Validations := Object clone do (
> >   validate := method(args,
> >     "validate" println
> >   )
> > )
> >  
> > Person := Object clone do (
> >   include(Validations)
> > )
> >  
> > Person println
>  
> outputs:
>  
> >  Validations_0x7fd8a8c8d440:
> >   type             = "Validations"
> >   validate         = method(args, ...)
> >   
>  
>  
> The type of Person is "Validations".
>  
> Then I try to call *include* after create Person:
>  
> > Person := Object clone
> >  
> > Person do (
> >   include(Validations)
> > )
>  
> outputs:
>  
> >  Person_0x7f90ab496ee0:
> >   type             = "Person"
> >   validate         = method(args, ...)
>  
>  
> This is my expectation. But I want to do all things in the prototype creation. How to write the corrective *include* method?
>  
>  
>