The Pickaxe book calls it scope resolution "operator", whereas The Ruby
Programming Language says it is not an operator because the righthand
side is not a value or expression but an identifier (which I think I
understand).
So, is :: an operator or not?
I would say no, because as far as I can tell, it can't be overloaded. Every
other operator can be overloaded in some context. It would be kind of cool if
it could -- for example, if the following worked:
class Decorated < BasicObject
def initialize klass
@klass = klass
end
def prettiness
"I'm decorated!"
end
def method_missing name, *args, &block
@klass.public_send name, *args, &block
end
end
module Decorate
def self.:
name)
Decorated.new Object.const_get(name)
end
end
Decorate::Integer.prettiness # <== "I'm decorated!"
Of course, you can also do this kind of hack with const_missing. So I guess if
:: is an operator, . is also, seeing as method_missing does the same thing. In
any case, the above doesn't work at all -- and regardless, I don't actually
have a use case beyond what people already hack with const_missing or
Kernel#autoload.
It's a fine semantic difference, though -- I don't think it matters whether
it's an operator or not.