Method Definitions

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...

Cheers,
Daniel

Hi --

···

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).

David

--
David A. Black
dblack@wobblini.net

David A. Black wrote:

Hi --

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).

David

Could you point me to one of those discussions? I wonder why such a proposal was turned down.

Cheers,
Daniel

···

On Fri, 18 Nov 2005, Daniel Schierbeck wrote:

Hi --

···

On Fri, 18 Nov 2005, Daniel Schierbeck wrote:

David A. Black wrote:

Hi --

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).

David

Could you point me to one of those discussions? I wonder why such a proposal was turned down.

Search for "make def return something useful"

David

--
David A. Black
dblack@wobblini.net

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

···

On 11/18/05, Daniel Schierbeck <daniel.schierbeck@gmail.com> 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.

--
Austin Ziegler * halostatue@gmail.com
               * Alternate: austin@halostatue.ca

David A. Black wrote:

Hi --

David A. Black wrote:

Hi --

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).

David

Could you point me to one of those discussions? I wonder why such a proposal was turned down.

Search for "make def return something useful"

David

This seems to be it:

http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/3e665f8b51fa62f4/c5fe597f51fa5f20?q="make+def+return+something+useful"&rnum=1

Though I can't really find a reason for `def' not to return a symbol. The discussion linked to seemed pretty unfocused.

Can anyone give me a good reason *not* to have `def' return a symbol?

Cheers,
Daniel

···

On Fri, 18 Nov 2005, Daniel Schierbeck wrote:

On Fri, 18 Nov 2005, Daniel Schierbeck wrote:

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.

Peter Vanbroekhoven may have firgured out the best way. He wrote a
patch to return a struct. You can find it here:

  http://rubyforge.org/projects/suby/

under 'def return struct'

T.

Daniel Schierbeck <daniel.schierbeck@gmail.com> writes:

Though I can't really find a reason for `def' not to return a
symbol. The discussion linked to seemed pretty unfocused.

Can anyone give me a good reason *not* to have `def' return a symbol?

Maybe it would make "load" weird...

class Foo
  def bar; end
end

# ---
load 'foo.rb' # => :bar

···

Cheers,
Daniel

--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org

Christian Neukirchen wrote:

Maybe it would make "load" weird...

class Foo
  def bar; end
end

# ---
load 'foo.rb' # => :bar

I don't follow... Can you elaborate?

Cheers,
Daniel

Daniel Schierbeck <daniel.schierbeck@gmail.com> writes:

Christian Neukirchen wrote:

Maybe it would make "load" weird...
class Foo
  def bar; end
end
# ---
load 'foo.rb' # => :bar

I don't follow... Can you elaborate?

Nevermind, I was wrong about the return value of Kernel#load.

···

Daniel

--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org