From: Colin Bartlett Date: 2011-01-12T23:58:10+09:00 Subject: Re: :: -- operator or not? On Wed, Jan 12, 2011 at 3:27 AM, David Masover wrote: > On Tuesday, January 11, 2011 05:16:24 pm Kedar Mhaswade wrote: >> ... The Ruby Programming Language says it is not an operator >> because the righthand side is not a value or expression but an identifier. >> 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's a fine semantic difference, though -- I don't think it matters whether > it's an operator or not. I agree. (Duck typing???) But trying to be picky, the "definition" from The Ruby Programming Language implies that a (binary) operator can operate on (two) arbitrary expressions, but that :: expects the second operand to be a constant or a method. So I'm not convinced that it's whether or not an operator can be overloaded that is relevant, as Anurag Priyam observed. The following seems to bear this out, although I'm a bit puzzled why "Q ::I" and "Q :: I" fail, but "(Q) :: I" and "q :: I" work. class Q p Q #=> Q q = Q p q #=> Q P = 355; I = 113 p Q::I #=> 113 p Q:: I #=> 113 (p (Q ::I)) rescue (p $!) #=> # (p (Q :: I)) rescue (p $!) #=> # p( (Q) :: I ) #=> 113 p q :: I #=> 113 i = I p i #=> 113 (p Q::i) rescue (p $!) #=> # end