Marnen Laibow-Koser wrote:
> Frederick Cheung wrote:
>> On Aug 12, 4:37�pm, Marnen Laibow-Koser <rails-mailing-l...@andreas-
>> s.net> wrote:
>>> are methods in Ruby. �Not all methods are operators, but that's another
>>> syntactic issue.
>> 
>> 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, << 
> *is* both.)

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:
"Foo".<<("bar")

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.

Example:
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?
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to