Thomas Adam
10/20/2007 6:49:00 PM
On 20/10/2007, Cedric Vicenti <ced_dude@hotmail.com> wrote:
> Hi guys,
>
> my ruby code is now a long file and I'd like to split it into different
> smaller files so that I could reuse them in different programs and make
> my original code smaller at the same time.
>
> One file should be used as the master and will reference the code of the
> other files.
>
> Is it feasible? Do I have to create some sort of a #include command or
> create function objects (I just need a code split, I do not want to
> create objects).
You should create Modules and allow them to be mixins to your Classes
via the "include" word. Example:
Module M
def some_func
"I am some_func"
end
end
class A
include M
end
foo = A.new
puts a.report
If "Module M" were in its own file, you coud then just "require" that
file, for instance.
-- Thomas Adam