ruby在类中访问@,类外访问调用方法
生活随笔
收集整理的這篇文章主要介紹了
ruby在类中访问@,类外访问调用方法
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
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}"
?
轉(zhuǎn)載于:https://www.cnblogs.com/fpcbk/p/10824991.html
總結(jié)
以上是生活随笔為你收集整理的ruby在类中访问@,类外访问调用方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HP MSA2000-硬盘leftove
- 下一篇: c#枚举