The toplevel (ie. main) can be quite aggravating when meta-
programming. For example:

  module Foo

    def self.included(base)
      base.extend Self
    end

    module Self

      def make_module_method(name)
          define_method(name) do |*args|
            "..."
          end
      end

    end

  end

  class Bar
    include Foo
    make_module_method('g')  # works
  end

  include Foo
  make_module_method('f')  # => error

Clearly there isn't uniformity between the toplevel namespace and
other namespaces. My code needs to take exception for the toplevel
with something like:

    def self.included(base)
      if TOPLEVEL == base  # how?
        base.include Self
      else
        base.extend Self
      end
    end

But off hand I'm not sure how --or at least don't recall of a way, to
do that.

Even if we got by this problem then #define_method would throw an
undefined method error -- it isn't defined at the toplevel -- you have
to define it yourself (which is why I wrote facets/main.rb btw, which
literally makes sure all module methods are defined in the toplevel --
a non-dynamic hack really.)

Some time ago, I suggested (more than once) that instead of delegating
the toplevel to Object, that it be made a self extended module. To me
that seems like the perfect solution --it's cleaner and achieves
everything the toplevel needs. Unfortunately I have never gotten any
discussion on this. Is it a bad idea> if so why? And if not, what
prevents Ruby for migrating to this design?

The future of Ruby's toplevel aside. At the moment I am facing this
issue once again. If anyone has a reasonable workaround. Please let me
know.

Thanks,
T.