Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Separating class and instance methods inside a module into submodules (ruby-like idiom)?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Roman Snitko  
View profile   Translate to Translated (View Original)
 More options May 30 2012, 4:11 am
From: Roman Snitko <roman.sni...@gmail.com>
Date: Wed, 30 May 2012 01:11:44 -0700 (PDT)
Local: Wed, May 30 2012 4:11 am
Subject: Separating class and instance methods inside a module into submodules (ruby-like idiom)?

(hope it's not too many questions in row, but I'm playing with JS.Class
really actively now).

I was trying to implement a ruby-like separation of class and instance
methods inside a module using `included`, here's what it looks like:

    Validatable = new JS.Module({

      InstanceMethods: new JS.Module({
        ...
      }),

     ClassMethods: new JS.Module({
       ...
     }),

    extend: {
      included: function(klass) {
        klass.include(this.klass.InstanceMethods);
        klass.extend(this.klass.ClassMethods);
      }
    }

  }

However, `this.klass.ObjectMethods` and `this.klass.ClassMethods` are
undefined. How do I get access to them correctly?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Coglan  
View profile  
 More options May 30 2012, 5:47 am
From: James Coglan <jcog...@gmail.com>
Date: Wed, 30 May 2012 11:47:52 +0200
Local: Wed, May 30 2012 5:47 am
Subject: Re: Separating class and instance methods inside a module into submodules (ruby-like idiom)?

On 30 May 2012 10:11, Roman Snitko <roman.sni...@gmail.com> wrote:

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().


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roman Snitko  
View profile   Translate to Translated (View Original)
 More options May 31 2012, 4:23 am
From: Roman Snitko <roman.sni...@gmail.com>
Date: Thu, 31 May 2012 01:23:38 -0700 (PDT)
Local: Thurs, May 31 2012 4:23 am
Subject: Re: Separating class and instance methods inside a module into submodules (ruby-like idiom)?

> 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?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Coglan  
View profile  
 More options Jun 5 2012, 11:35 am
From: James Coglan <jcog...@gmail.com>
Date: Tue, 5 Jun 2012 16:35:02 +0100
Local: Tues, Jun 5 2012 11:35 am
Subject: Re: Separating class and instance methods inside a module into submodules (ruby-like idiom)?

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.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »