ruby - Attach included class to namespace? -


this question has answer here:

i have ruby class bar in file models/bar.rb:

class bar end 

and ruby module foo in main program file:

module foo end 

i require/load/autoload bar such it's namespaced under foo, i.e.:

module foo   autoload :bar, 'models/bar.rb' end  fb = foo::bar.new # yay! 

however, entities found require/load/autoload attached global namespace. in order work, have edit models/bar.rb , wrap class in module foo..end. there way without having that?

no. impossible under normal file loading. (if read file models/bar.rb not ruby code string, , instance_eval string within foo, possible.)


Comments