什么::
啊
@song ||= ::TwelveDaysSong.new
Ruby ::(双半冒号)
顶级常量由双冒号引用
class TwelveDaysSong
end
a = TwelveDaysSong.new
#I could wrote it like this too
a = ::TwelveDaysSong.new
module Twelve
class TwelveDaysSongs
end
end
b = Twelve::TwelveDaysSong.new
#b is not equal to
a = ::TwelveDaysSong.new
#neither
a = TwelveDaysSong.new
类也是常量,所以如果您有常量
HELLOWOLRD = 'hw'
你可以这样称呼它 ::HELLOWORLD
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句