From: Brian Candler Date: 2010-02-09T22:47:16+09:00 Subject: Re: Mixin module with class variables and class methods John Lane wrote: > Can someone advise how this should be written so that a class method in > a mixin can access a class variable created by the mixin ? Class variables are a pain, for exactly this sort of reason. Instance variables of a class are much easier to handle and understand. module TestMixin def self.included(base) p "TextMixin included in #{base}" base.class_eval { @name = "foobar" } base.extend ClassMethods end module ClassMethods def name @name end def name=(x) @name=(x) end def class_method(str) $stderr.puts "this is a class method in TestMixin #{str}" $stderr.puts "the class variable is #{name}" end end def name self.class.name end def name=(x) self.class.name=(x) end def instance_method $stderr.puts "this is an instance method in TextMixin" $stderr.puts "the class variable is #{name}" end end class Foo include TestMixin class_method "foo" def initialize instance_method end end Foo.new -- Posted via http://www.ruby-forum.com/.