Re: How to write *include* like Ruby?
Kurtis Rainbolt-Greene <[email protected]> Sat, 19 May 2012 15:21:04 -0500
| Newsgroups | gmane.comp.lang.io |
|---|---|
| Message-ID | <CAMhJPGhT9dfHQ5pc6zrWGS-AZBZEtbP_1mnTL30WvBkZnpQOGg@mail.gmail.com> |
This is something I've been thinking about heavily over the last two days, so I'm glad to see someone else post about it. On Sat, May 19, 2012 at 9:48 AM, lijie <[email protected]> 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? > > > >