From: John Doe Date: 2010-10-25T22:58:57+09:00 Subject: Need help with class variables and inheritance Hi, Suppose i wrote something like this: class TestClass @@testmethod = lambda { puts "inside testmethod" } def method_missing(name, *args) eval("@@#{name}").call(*args) end end irb(main):002:0> TestClass.new.testmethod inside testmethod It works fine but if I have more classes i don't want to duplicate the same method_missing. I thought i could write this: class TestSuperClass def method_missing(name, *args) eval("@@#{name}").call(*args) end end class TestSubClass < TestSuperClass @@testmethod = lambda { puts "inside testmethod" } end but then i get this error: irb(main):003:0> TestSubClass.new.testmethod NameError: (eval):1:in `method_missing': uninitialized class variable @@testmethod in TestSuperClass Is there any way to get it to work? -- Posted via http://www.ruby-forum.com/.