From: Brian Candler Date: 2009-12-16T23:31:51+09:00 Subject: Re: Split Module to multiple Files? Christian Kerth wrote: > Hey! > > Is it possible to achieve somthing like this: > > I want to have multiple classes, each in one file > > e.g. > > test.rb -> class Test > test1.rb -> class Test1 > > Then i want to combine those classes into a module > > myModule.rb -> module myModule That depends what you mean by "combining those classes into a module". Do you mean that you want these classes to appear under the MyModule namespace? You could simply do: require 'test' require 'test1' module MyModule Test = ::Test Test1 = ::Test1 end Now you can use MyModule::Test.new (or whatever) You still have the top-level constants Test and Test1. You can get rid of them using remove_const, although it looks like the class will still think its name is "Test" rather than "MyModule::Test" >> class Test; end => nil >> module MyModule; Test = ::Test; end => Test >> MyModule::Test => Test >> Object.instance_eval { remove_const(:Test) } => Test >> Test NameError: uninitialized constant Test from (irb):8 from :0 >> MyModule::Test => Test >> But at the end of the day, I'd question what it is you're actually trying to do. Normally it would make more sense just to add module MyModule ... end to test.rb and test1.rb -- Posted via http://www.ruby-forum.com/.