A
Andrew Walrond
I want to wrap a pile of classes, which are defined in their own files, inside
a wrapper module. Basically, I want this to work:
glibc.rb:
class Glibc
end
test.rb:
module Packages
load 'glibc.rb'
end
Packages::Glibc.new
But it doesn't do what I expected. Glibc gets added to the global namespace,
rather than the Packages namespace.
I.e. Glibc.new works; Packages::Glibc.new doesn't
Now, I see Kernel.load() is documented as
Kernel.load(filename,wrap=false)
If wrap==true, then "the loaded script will be executed under an anonymous
module, protecting the calling program's global namespace"
I guess I need the equivalent of
Kernel.load(filename,wrapper_module=nil)
So I can do
load('glibc.rb',Packages)
Or is there another way?
Suggestions appreciated
Andrew Walrond
PS Explicitly putting Packages:: on each class definition is possible, but
there are 000s of packages so I was looking for a better way....
a wrapper module. Basically, I want this to work:
glibc.rb:
class Glibc
end
test.rb:
module Packages
load 'glibc.rb'
end
Packages::Glibc.new
But it doesn't do what I expected. Glibc gets added to the global namespace,
rather than the Packages namespace.
I.e. Glibc.new works; Packages::Glibc.new doesn't
Now, I see Kernel.load() is documented as
Kernel.load(filename,wrap=false)
If wrap==true, then "the loaded script will be executed under an anonymous
module, protecting the calling program's global namespace"
I guess I need the equivalent of
Kernel.load(filename,wrapper_module=nil)
So I can do
load('glibc.rb',Packages)
Or is there another way?
Suggestions appreciated
Andrew Walrond
PS Explicitly putting Packages:: on each class definition is possible, but
there are 000s of packages so I was looking for a better way....