From: Michael Neumann Date: 2004-12-02T01:03:03+09:00 Subject: Re: [OFF] Python 2.4 released Austin Ziegler schrieb: > On Wed, 1 Dec 2004 19:14:25 +0900, Michael Neumann wrote: > >>If the Ruby parser could determine, whether a "def" statement is used inside >>another expression (e.g. "public def"), then it would be great if it would >>return a Method object. If it's in no expression (plain class/module scope), >>it should return nil. Not sure, if this is possible at all. A Method object >>is much better than a Symbol! > > > Why? Okay, it's not *much* better ;-) Symbols are fine most of the time. Well, you may remeber that I tried to implement Pythons decorators in Ruby: http://www.ntecs.de/blog/Blog/PythonDecorators2.rdoc And then I tried to implement the same in other ways, e.g. synchronize | def f end or synchronize private <= def f end (or use other operators). But that does not work with symbols, as synchronize would create an object which does not have the current binding (I tried binding_of_caller IIRC, but that didn't worked either). In this case, the method object would be nice. But that is a very rare case. > I ask this in all seriousness, because just about the only thing > (currently) that you can get from a Method and not from a Symbol is > #arity. While I certainly wish I could get other information, there's > little value in returning a heavyweight object. Beyond that, I don't > think that it's useful to have a dynamic return (similar to Perl's > "wantsarray" -- ick!). No. I fully agree. > Most operations where this is desired are things that work better with > the name of the method than the Method or UnboundMethod itself. As far > as I can tell, there's no method to get the name of the Method or > UnboundMethod, so you're stuck with parsing #inspect. Maybe this could be implemented. > I do think that we have to figure out what "def self.foo; ... ; end" > should return if we do this and have commented such on RCR 277. Hm, here, a method object would help. Or, as someone else suggested, a [scope, :symbol] as return value should help, right? That's of course more overhead than just a simple symbol. The question is how much more expensive would a method object be? Regards, Michael