Marnen Laibow-Koser wrote:
Frederick C. wrote:
On Aug 12, 4:37ï¿½pm, Marnen Laibow-Koser <rails-mailing-l…@andreas-
are methods in Ruby. ï¿½Not all methods are operators, but that’s another
If we’re being pedantic, then not all operators are methods: ! is not
a method, nor is ?: and != is hardwired to be the negation of ==
(there are a few others eg &&, :: et.)
Ack, you’re right. I keep forgetting that unlike Smalltalk or C++, not
every operator is a method call. Sorry about the error. (However, <<
First, sorry for the added confusion, but it was actually constructive
since I learned something. I hadn’t really thought about how blurred the
line has become between operators and methods/functions. Back in the day
(the C days that is) it was fairly clear the difference between the two.
In OOP land not so much.
I suppose the determining factor in languages like Ruby is more in how
operators and methods are used syntactically, rather than where and how
they are actually defined by the language.
For example you could write the syntax this way:
which would be the same as:
“Foo” << “bar”
So would we call “<<” in the first syntax a method, and “<<” in the
second syntax an operator?
Also given that the “<<” can have drastically different meaning based on
the class of the objects I support I think about “<<” more as a method
than an operator.
10 << 4
=> 160 (bit-wise shift left by 4)
Is there really a valid distinction between operators and methods
anymore? Isn’t the syntax essentially “syntactic sugar” allowing for
simplified use of some of the methods?