的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