Hi, I''m playing around with module instance variables. I can set one up and initialise it when the module is included in a class. What I can''t work out is how I initialise one when a class inherits another class that includes the module. See http://pastie.org/905720 This creates two classes, the first inherits a module that contains an instance variable. The second inherits the first. The instance variable in the first class is initialised as expected, the second (inherited one) is not. The output I get is below: the data for class One is Tue Apr 06 15:10:43 +0000 2010 the data for class Two is How should I modify the module so that the initialisation takes place when the module is included via inheritance ? Thanks. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Apr 6, 4:12 pm, John Lane <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, I''m playing around with module instance variables. I can set one up > and initialise it when the module is included in a class. What I can''t > work out is how I initialise one when a class inherits another class > that includes the module. > > Seehttp://pastie.org/905720 > > This creates two classes, the first inherits a module that contains an > instance variable. The second inherits the first. The instance variable > in the first class is initialised as expected, the second (inherited > one) is not. The output I get is below: > > the data for class One is Tue Apr 06 15:10:43 +0000 2010 > the data for class Two isYou''ve got class instance variables which (unlike class variables) aren''t shared around the inheritance hierachy at all. This is a slightly murky area which I wrote a bit about here: http://www.spacevatican.org/2008/8/19/fun-with-class-variables Searching for class instance variables should also turn up some interesting reading material. Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> This is a slightly murky areaA murky area indeed. Been away from it for a few days but just sorted myself out with your help. Scope when playing with module that extend classes is little short of a nightmare. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.