如何將單個值附加到作爲類對象存儲的數組引用?如何將單個元素添加到數組對象
class Citations
attr_accessor :paper,:arr
def dothing()
return paper.to_s.length
end
end
cit = Citations.new
#(1...5).each{ |x| cit.arr << x } # fails
cit.arr = [1,2,3,4] # works if I add the entire array as one unit
puts cit.arr