At the moment, “obj::foo” means the same as “obj.foo”; that is,
“obj.send(:foo)”.
I propose that it be changed to mean “obj.method(:foo)” instead.
Although the obj.foo syntax is generally preferred, the obj::foo syntax
is commonly used for class methods in the standard library, so I assume
such a change is too incompatible for use in the 1.8 branch.
This would provide simpler access to method objects in case you want to
use them functionally, pass them around as blocks, etc. It would mean
that (as in Python, C++ and other languages) it’s as easy to refer to a
method object as to call the method, whereas currently that requires a
wordy method call.
We don’t need two such similar ways to call a method - the dot is fine.
At the moment, “obj::foo” means the same as “obj.foo”; that is,
“obj.send(:foo)”.
I propose that it be changed to mean “obj.method(:foo)” instead.
I’m just not sure that method objects are accessed frequently enough to
justify such a syntax. Furthermore, if we were to introduce a
shorthand syntax for accessing method objects, why not use a syntax that
isn’t currently in use?
At the moment, “obj::foo” means the same as “obj.foo”; that is,
“obj.send(:foo)”.
They’re not the same:
$ irb
irb(main):001:0> class Test
irb(main):002:1> class InnerTest
irb(main):003:2> end
irb(main):004:1> end
=> nil
irb(main):005:0> Test.InnerTest
NoMethodError: undefined method `InnerTest’ for Test:Class
from (irb):5
from :0
irb(main):006:0> Test::InnerTest
=> Test::InnerTest
irb(main):007:0>
wordy method call.
method (six characters) is not wordy at all. Method objects are
convenient, but I don’t think that justifies special syntax.
We don’t need two such similar ways to call a method - the dot is fine.
On Fri, 2006-06-02 at 19:25 +0900, Daniel S. wrote:
obj->foo
obj~foo
I’ve been watching the related thread on the newsgroup, and I agree with
Daniel, in that I’ve not used #method enough to make it worthwhile
having a special syntax for it, and even if we did I think :: is
confusing enough already.
(Aside: Current ruby 1.9 has an experimental lambda syntax involving the
-> operator).