Re: How to write *include* like Ruby?
Jeremy Tregunna <[email protected]> Sat, 19 May 2012 14:23:07 -0600
| Newsgroups | gmane.comp.lang.io |
|---|---|
| Message-ID | <[email protected]> |
This happens because if an object doesn't have a type slot (which a fresh Object clone won't) we copy over the type slot in the trait. If this is really not a big deal at all, since anyone doing type comparison based on the type slot should have more common sense. I'd like to deprecate the type slot actually, but it's presently used in output in the REPL. Alternatively, you can always ignore the type slot, but that will require changing A0_Object.io in libs/iovm/source/io and I would strongly not recommend this at all. 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? > > >