如何为数组创建 attr_accessor?
例如
class MyClass
attr_accessor :my_attr_accessor
def initialize()
end
def add_new_value(new_array)
@my_attr_accessor += new_array
return @my_attr_accessor
end
end
my_class = MyClass.new
my_class.my_attr_accessor = 1
my_class.my_attr_accessor[1] = 2
my_class.my_attr_accessor.push = 3
my_class.add_new_value(5)
my_class.my_attr_accessor
=> [1, 2, 3, 5]