> However, `this.klass.ObjectMethods` and `this.klass.ClassMethods` are
> undefined. How do I get access to them correctly?
To explain what's going on here: you've made InstanceMethods and
ClassMethods as instance properties of the Validatable module, so they will
become instance properties of whatever you mix the module into. The the
included() function, `this` refers to the Validatable module, so the value
of `this.klass` is Module.
What you probably want to do is move the modules into the `extend` block,
and just use `this.InstanceMethods` to refer to them in included().
> To explain what's going on here: you've made InstanceMethods and > ClassMethods as instance properties of the Validatable module, so they will > become instance properties of whatever you mix the module into. The the > included() function, `this` refers to the Validatable module, so the value > of `this.klass` is Module.
> What you probably want to do is move the modules into the `extend` block, > and just use `this.InstanceMethods` to refer to them in included().
Yes, thank you for the explanation, makes a lot of sense, actually. It works. However, I must ask you a bit more about included(). This is from the docs:
In the same vein, if you include() a module that has a singleton method
> called included, that method will be called. This effectively allows you > to redefine the meaning of include for individual modules.
Yet you're saying that InstanceMethods and ClassMethods, if defined as module's instance properties, become instance properties of whatever I mix the module into. Does that mean that included() is simply a callback and by providing this callback I don't prevent module's instance properties from mixing in?
On 31 May 2012 09:23, Roman Snitko <roman.sni...@gmail.com> wrote:
> However, I must ask you a bit more about included(). This is from the docs:
> In the same vein, if you include() a module that has a singleton method
>> called included, that method will be called. This effectively allows you
>> to redefine the meaning of include for individual modules.
> Yet you're saying that InstanceMethods and ClassMethods, if defined as
> module's instance properties, become instance properties of whatever I mix
> the module into. Does that mean that included() is simply a callback and by
> providing this callback I don't prevent module's instance properties from
> mixing in?
Yes, I guess the docs are misleading here. The baseline behaviour of
include() is *always* to mix properties in and add the module to the
ancestor chain. included() lets you define *additional* behaviour, not
replace the existing behaviour.