def things
should be def self.things
That makes it a class method rather than an instance method.
Вопрос
So I want to be able to define a class like this:
class MyHouse < Home
things :bed, :lamp, :chair
end
Where Home takes care of putting those "things" in an array, like this:
class Home
attr_accessor :things
def things(*things)
@things = []
things.each { |thing| @things << thing }
end
end
The problem with this is I get:
NoMethodError: undefined method `things' for MyHouse:Class
I know there's a way to do this. Help appreciated,
Thanks,
Pachun
Решение
def things
should be def self.things
That makes it a class method rather than an instance method.