ruby的实例变量

class Box
  def initialize(w,h)
    @width,@height=w,h
  end
  def getArea
    @height*@width
  end
end
class BigBox <Box
  def printArea
    @area=@width*@height
    puts "#@area"
  end
  def getArea
    puts "bigbox 的面积是 #@area "
  end
end
box =BigBox.new(12,12)
box.printArea//只有加上这个,area才有值
box.getArea
原文地址:https://www.cnblogs.com/fpcbk/p/10825163.html