Different types of include

How is an ‘include’ outside of a module different from one inside a
module. Where does the outer ‘include’ come from (the only documented
include method is on Module).

The following code works:

require 'fox’
include Fox
module MyModule
class MyClass
def hello; puts FXTreeList; end
end
end

The following does not:
module MyModule
require 'fox’
include Fox
class MyClass
def hello; puts FXTreeList; end
end
end

I was under the impression that part of the mechanism of include was to
include the constants defined in the other module.

Is the only way to keep your namespace clean to use Fox::FXTreeList
everywhere and avoid top-level includes?

(this isn’t a problem with fox, due to the fact that fox always has FX
on the classname prefix, but I can see that it could be a problem with
other modules).

Daniel Sheppard
http://jroller.net/page/soxbox

···

#####################################################################################
This email has been scanned by MailMarshal, an email content filter.
#####################################################################################

How is an ‘include’ outside of a module different from one inside a
module. Where does the outer ‘include’ come from (the only documented
include method is on Module).

The following code works:

require ‘fox’
include Fox
module MyModule
class MyClass
def hello; puts FXTreeList; end
end
end

The following does not:
module MyModule
require ‘fox’
include Fox
class MyClass
def hello; puts FXTreeList; end
end
end

I was under the impression that part of the mechanism of include was to
include the constants defined in the other module.

Yes. The first example includes Fox in Object, hence making its constants
visible to all objects. The second example includes it in MyModule, not in
MyClass, so its constants become directly visible to MyModule, not to
MyClass. So the following does work:

module MyModule
require ‘fox’
class MyClass
include Fox
def hello; puts FXTreeList; end
end
end

Or this does, but then instead of Fox::FXTreeList, you’d need to type the
longer MyModule::FXTreeList :

module MyModule
require ‘fox’
include Fox
class MyClass
def hello; puts MyModule::FXTreeList; end
end
end

Peter