From: Dan Doel Date: 2003-08-16T08:20:31+09:00 Subject: Re: Overloading () Dave Benjamin wrote: > I understand that everything lives inside an object, so there are no free > >functions, but there are certainly methods that behave like free functions; >I can create one of those things using "def". What I can't seem to do is >pass that method around and still call it without referencing the object >it's attached to. Or can I? > You can't, as far as I know. Using def outside of a class doesn't really create a free function object. It creates a method in the current class/module context (not sure what that is. Kernel?). So the reason you can do def foo; end foo() Is because you're calling a method, not using a callable object. The callable object would be accessible via method(:foo) Which gets the method bound to the symbol foo from the current class/module context. So you'd do m = method(:foo) m[] The big controversy is that if you allow callable objects with normal method calling semantics, what does m contain in: m = foo.a Is m the result of calling the #a method of foo? Or is it the #a method of foo itself? If you don't allow callable objects with normal method calling conventions, you don't run into this debate. Also, for a more complex argument, how do you treat: m = foo.a b c ? Does foo.a return a callable object to which you pass b and c as arguments, or do you pass b and c to a? If the latter is the behavior, but you want the former, you'd need m = foo.a() b c Which looks weird. So having callable objects with normal method calling syntax makes things a lot more complicated, which is, I imagine why ruby doesn't have them. Calling methods of an object doesn't directly use the method objects, at least as far as the code is concerned. Hope this helps some. - Dan