You don't, unless you can guarantee to always use a specific mapping
between directory structures and namespaces - none is enforced (nor
could be enforced) in Ruby, as it is in, say, Java class file loading.
Ok, but there is a way to accomplish what I needed, anyhow. I
switched to putting my functions into classes that inherit from a
common base. When the plugin files are loaded, ruby calls the
.inherited method on my base class, which tells me that new plugins
have been registered. At least there's a way to track some activity,
if not all activity.
The code being run on require could change anything, through monkey
patching, ObjectSpace, etc, even changing running object instances.
Yeah, I expect that to be the case; I just wish ruby had sane
namespacing of the introduction of constants. I guess it wouldn't
matter, since things like monkey-patching are so popular in ruby, so
the effects of a single file would rarely be contained in its
namespace anyhow, but I've always been irritated by the fact that
loading a file doesn't give any hint as to what new modules/classes
have been introduced to the global namespace. Am I alone in this
view?
Even when a library does use modules, it doesn't generally give clean
namespacing. For example, the 'drb' library wraps all its code in the
DRb module, but then lifts some of its classes into the global
namespace:
Module.constants.sort.grep /drb/i
=>
require 'drb'
=> true
Module.constants.sort.grep /drb/i
=> [:DRb, :DRbIdConv, :DRbObject, :DRbUndumped]
Shouldn't the DRbIdConv, DRbObject, and DRbUndumped just stay under
the DRb module? They're promoted to the global namespace at the
bottom of drb/drb.rb, but why is this considered a good idea? Are
hygenic namespaces considered ugly in ruby?