ruby在类中访问@,类外访问调用方法
生活随笔
收集整理的这篇文章主要介绍了
ruby在类中访问@,类外访问调用方法
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
class Boxdef initialize(w,h)@width,@height=w,hend def printWidthputs @widthenddef printHeight@height*12end
puts @width,"asfd" 这访问不了,只能在实例方法中访问,这里代表类实例class
end box =Box.new(1,12) x=box.printHeight box.printWidth puts "#{x}"
puts @width,"asfd" 这访问不了,只能在实例方法中访问,这里代表类实例class
end box =Box.new(1,12) x=box.printHeight box.printWidth puts "#{x}"
转载于:https://www.cnblogs.com/fpcbk/p/10824991.html
总结
以上是生活随笔为你收集整理的ruby在类中访问@,类外访问调用方法的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: HP MSA2000-硬盘leftove
- 下一篇: 微软职位内部推荐-Principal S