Rails: i have a class method and i want to modify something of the instance
something like this:
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
that is similar to the model classes:
# in the model
has_many :projects
How do I do it?
EDIT:
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