所以我希望能够像这样定义一个类:
class MyHouse < Home
things :bed, :lamp, :chair
end
Home 负责将这些“东西”放入数组中,如下所示:
class Home
attr_accessor :things
def things(*things)
@things = []
things.each { |thing| @things << thing }
end
end
问题是我得到:
NoMethodError: undefined method `things' for MyHouse:Class
我知道有办法做到这一点。帮助表示赞赏,
谢谢,
帕春