J
John Doe
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?
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?