我有一个名为 的类,Product其中包含一个name和。pricecount
在另一个名为Shop(包括 class Product)的类中,我用一个空数组进行初始化。然后使用 方法添加product到这个数组中push。
问题发生to_s在Shop类中的方法上:
def to_s
string = "Products in the shop:\n"
@list.each do |list|
#### how can i get access to the attributes of product like @list.name or something like that ? I have tried loads of different methods but i cant get access to my attributes. (the array doesnt recognize the product class)
puts @list.name
end
Product如果我在不使用的情况下创建 a Array,我可以访问属性 - 我猜问题出在Array...