[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Split Module to multiple Files?

Christian Kerth

4/2/2008 11:24:00 AM

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

thx
--
Posted via http://www.ruby-....

1 Answer

Martin Boese

4/2/2008 1:53:00 PM

0


You can do:

== myModule.rb
module MyModule
eval File.open('test1.rb').read
eval File.open('test2.rb').read
end


But this would be ugly, the better way IMO is to define the classes
individually within modules:

== test.rb:
module MyModule
class Test
(...)
end
end

== test2.rb:
module MyModule
class Test2
(...)
end
end

== myModule.rb
require 'test'
require 'test2'


Martin


On Wednesday 02 April 2008 12:24:01 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
>
> thx