的Rails的东西:我有一个类的方法,我想修改实例的东西Rails的:我有一个类的方法,我想修改实例
是这样的:
class Test < Main
template :box
def test
# here I want to access the template name, that is box
end
end
class Main
def initialize
end
def self.template(name)
# here I have to save somehow the template name
# remember is not an instance.
end
end
这与模型类相似:
# in the model
has_many :projects
我该怎么做?
编辑:
class Main
def self.template(name)
@name = name
end
def template
Main.instance_eval { @name }
end
end
class Test < Main
template 6
end
t = Test.new.template
t # t must be 6
您是否考虑过将您的一些问题标记为已回答? – DJTripleThreat 2010-06-06 08:56:27