来啦,已经跑了好几圈啦....
Canvas is not supported in your browser.

ruby在类中访问@,类外访问调用方法

class Box
  def initialize(w,h)
    @width,@height=w,h
  end 
  def printWidth
    puts @width
  end
  def printHeight
    @height*12
  end

puts @width,"asfd" 这访问不了,只能在实例方法中访问,这里代表类实例class

end

box =Box.new(1,12)
x=box.printHeight
box.printWidth
puts "#{x}"

 

posted @ 2019-05-07 13:51  fangpengcheng_方鹏程  阅读(321)  评论(0编辑  收藏  举报