Matt9
28 February 2009 22:54
1
In this phrase:
class IterString < ::String
# whatever
end
what do the double-colons do? Thx - m.
···
--
matt neuburg, phd = matt@tidbits.com , http://www.tidbits.com/matt/
Leopard - http://www.takecontrolbooks.com/leopard-customizing.html
AppleScript - http://www.amazon.com/gp/product/0596102119
Read TidBITS! It's free and smart. http://www.tidbits.com
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.
···
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.
--
Aaron Patterson
http://tenderlovemaking.com/
Matt9
1 March 2009 01:09
3
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.
···
Aaron Patterson <aaron@tenderlovemaking.com> wrote:
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.
The double colons make sure that ruby looks at the top level for the constant.
--
matt neuburg, phd = matt@tidbits.com, Matt Neuburg’s Home Page
Leopard - http://www.takecontrolbooks.com/leopard-customizing.html
AppleScript - http://www.amazon.com/gp/product/0596102119
Read TidBITS! It's free and smart. http://www.tidbits.com