最佳答案
attr_accessor
在以下代码上无法工作。错误显示“ undefined method 'things' for Parent:Class (NoMethodError)
”:
class Parent
@@things = []
attr_accessor :things
end
Parent.things << :car
p Parent.things
但是下面的代码可以工作吗
class Parent
@@things = []
def self.things
@@things
end
def things
@@things
end
end
Parent.things << :car
p Parent.things