Classes are open. So are modules. You can define your module in 2 files as =
Jesus described.

To use the module, you need to require both files.

require 'file1'
require 'file2'

Hope this helps.

Best,
Jingjing


-----Original Message-----
From: Jes=FAs Gabriel y Gal=E1n [mailto:jgabrielygalan / gmail.com]=20
Sent: Monday, November 07, 2011 8:33 AM
To: ruby-talk ML
Subject: Re: How to include a function from a different file in a module

On Mon, Nov 7, 2011 at 5:29 PM, Andreas L.
<andreas.lundgren / takepoint.se> wrote:
> Hi!
>
> Would it be possible to have a module with one or several of its methods
> (source code) stored in a different file?
>
> Something like this with "func_b" stored in a different file than the
> module.
>
> _________file1.rb_________
> module MyModule
> =A0 def func_a
> =A0 =A0 =A0...
> =A0 end
>
> =A0 require "file2.rb"
>
> end
>
> _________file2.rb_________
> def func_b
> =A0 ...
> end
>
> (This gived the error "private method `func_b called for MyModule:Module
> (NoMethodError)")

In file2.rb you have to place func_b inside the module too:

 _________file2.rb_________
module MyModule
  def func_b
    ...
  end
end

Jesus.