From: Jonas Pfenniger Date: 2006-07-14T22:16:45+09:00 Subject: Re: About MyClass#my_method On 14/07/06, dblack@wobblini.net wrote: > On Fri, 14 Jul 2006, Jonas Pfenniger wrote: > > I always see the # notation in the docs to design instance_methods. > > Wouldn't it be nice to be able to use that notation to address and > > access methods directly ? > > > > MyClass#my_method would replace MyClass.instance_method(:my_method) > > > > and > > > > def MyClass#my_method end would replace class MyClass; def my_method end end > > That syntax is already taken, for comments. I know but other characters are used differently in various circumstances. For example {} is for a hash or a block depending where it is in the code. I would really like that the dot notation would only be used for method calls. > > Similarily, I was also thinking that :: could be used for class methods. > > I'd be glad to see :: for method *calls* disappear, but I doubt it > will and therefore it's not available. Also, both method names and > constants can start with uppercase letters, which I think would make > parsing this impossible. Yeah this is a good argument. Actually, the edge case would be when you have a method and a constant with the same name and that you want to access to the method's instance. Like : class Test end def Test::LibPath; "." end Test::LibPath = File.dirname(__FILE__) Test::LibPath would always give the dirname of __FILE__. But in that case you could use Test.method(:LibPath) If you want to call that method, you would alread do Test.LibPath like in the actual ruby implementation. The def keywork would allow to make the distinction while parsing. -- Cheers, zimbatm http://zimbatm.oree.ch