From: Austin Ziegler Date: 2005-11-19T00:39:57+09:00 Subject: Re: Method Definitions On 11/18/05, Daniel Schierbeck wrote: > David A. Black wrote: >> On Fri, 18 Nov 2005, Daniel Schierbeck wrote: >>> Just a little curiosity: If method definitions (`def foo; end') were >>> to return a symbol representing the method's name (`:foo' in this >>> case) rather than just nil, would this be possible? >>> >>> class Klass >>> private def foo >>> "Klass#foo" >>> end >>> >>> def bar >>> "Klass#bar" >>> end >>> end >>> >>> obj = Klass.new >>> obj.bar -> "Klass#bar" >>> obj.foo -> private method `foo' called... >> Yes; I think that's one of the main things people who advocate this >> want to be able to do (just remembering [I think] from earlier >> discussions). > Could you point me to one of those discussions? I wonder why such a > proposal was turned down. As a big proponent of making def return something useful, it was turned down in part because what would def return to be passed into private with: class Klass private def self.foo "Klass.foo" end end If you simply do :foo, then you would be applying private to Klass#foo -- which isn't what you want. But returning more than :foo isn't kosher either since private doesn't (at this point) know what to do with it. I *think* Matz would be at least partially in favour of this if we could figure out something useful and lightweight to return that wouldn't prevent the above code. -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca