From: dblack@... Date: 2006-07-14T23:20:30+09:00 Subject: Re: About MyClass#my_method Hi -- On Fri, 14 Jul 2006, Jonas Pfenniger wrote: > 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. OK, then let me put it differently: repurposing comment syntax is a bad idea :-) I really think that comments are important enough that they deserve a completely unchallenged syntax. (I know about "#{}". I consider the quotation marks a mitigating factor: "#" wouldn't be a comment anyway.) > 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) So you'd have to know whether there was a method of the same name... which I think is very fragile. David -- http://www.rubypowerandlight.com => Ruby/Rails training & consultancy http://www.manning.com/black => RUBY FOR RAILS (reviewed on Slashdot, 7/12/2006!) http://dablog.rubypal.com => D[avid ]A[. ]B[lack's][ Web]log dblack@wobblini.net => me