Matthew Johnson wrote:
> > Almost. But that's sort of reverse the situation. Will we have to add
> > 'self.' to every call b/c there's the chance someone will define a
> > toplevel method when using our libs?
>
> You won't need to add self to every call, only to calls which may end
> up in method_missing.  If the method is guaranteed to exist in the
> object or one of its ancestors self is not necessary to ensure the
> expected method is called.  Expecting calls to self to end up in
> method_missing seems like a pretty specialized case...

Sure. All of this is a specialized case. It's a specialized case to use
the toplevel to purposefully add methods to Object. Toplevel methods
aren't that common in the first place, except in one-off scripts. But
if you actaully are utilizng the toplevel, for instance in mycase where
end-users are writting mini task scripts, then these specialized cases
come to bare strongly.

So far his is what I have had to deal with:

  1. Manually add #define_method, #ancestors, &c. to proxy to Object
class.
  2. Be careful b/c Toplevel and Object class 'self' can get mixed-up.
  3. Avoid using #send if you're utilizing method_missing (util 1.9)
  4. Add 'self.' prefix to internal methods if purposefully invoking
method_missing.

And I wouldn't be suprised if their are others.

So it's not that this is a huge issue, obviously. But why have these
issues at all if it's completely and easily avoidable? Using a self
extended module (Main) for the toplevel avoids all of this. And if, for
some reason, one needs to add their top level methods to all objects,
'class Object; include Main; end' is a very simple solution.

T.