In this phrase:
class IterString < ::String
whatever
end
what do the double-colons do? Thx - m.
In this phrase:
class IterString < ::String
end
what do the double-colons do? Thx - m.
On Sun, Mar 01, 2009 at 07:54:03AM +0900, matt neuburg wrote:
In this phrase:
class IterString < ::String
whatever
end
what do the double-colons do? Thx - m.
It’s explicitly telling ruby where to find the “String” constant.
For example:
module Foo
class String
def hello
“world”
end
end
class Bar < String
end
class Baz < ::String
end
end
puts Foo::Bar.new.hello
puts Foo::Baz.new.hello # => (NoMethodError)
The double colons make sure that ruby looks at the top level for the
constant.
Aaron P. [email protected] wrote:
The double colons make sure that ruby looks at the top level for the constant.
Right, I see, I was testing it in a place where String and ::String were
the same; that’s why I couldn’t see a difference. Thx - m.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs