# File lib/tour/facets/module/method_space.rb, line 25
  def method_space(name, mod=nil, &blk)

    ## If block is given then create a module, otherwise
    ## get the name of the module.
    if block_given?
      name = name.to_s
      raise ArgumentError if mod
      mod  = Module.new(&blk)
    else
      if Module === name
        mod = name
        name = mod.basename.downcase
      end
      mod  = mod.dup
    end

    ## Include the module. This is neccessary, otherwise
    ## Ruby won't let us bind the instance methods.
    include mod

    ## Save the instance methods of the module and
    ## replace them with a "transparent" version.
    methods = {}
    mod.instance_methods(false).each do |m|
      methods[m.to_sym] = mod.instance_method(m)
      mod.module_eval %{
        def #{m}(*a,&b)
          super(*a,&b)
        end
      }
      ##mod.instance_eval do
      ##  define_method(m)
      ##    super
      ##  end
      ##end
    end

    ## Add a method for the namespace that delegates
    ## via the Functor to the saved instance methods.
    define_method(name) do
      mtab = methods
      Functor.new do |op, *args|
        if meth = mtab[op.to_sym]
          meth.bind(self).call(*args)
        else
          #self.__send__(op, *args)
          raise NoMethodError, "undefined method `#{m}'"
        end
      end
    end
  end