From: Daniel Vartanov on
Hi! I want to replace "default definee" when I require ruby file.

A short example: http://gist.github.com/461094

Of course, it says that One::Configuration is an uninitialized constant.

So, here is my question: how to require configN.rb so that all
definitions are done inside the module?

Thanks in advance,
Daniel.
--
Posted via http://www.ruby-forum.com/.

From: Lee Jarvis on
[Note: parts of this message were removed to make it a legal post.]

On 2 July 2010 09:21, Daniel Vartanov <daniel.vartanov(a)gmail.com> wrote:

> Hi! I want to replace "default definee" when I require ruby file.
>
> A short example: http://gist.github.com/461094
>
> Of course, it says that One::Configuration is an uninitialized constant.
>
> So, here is my question: how to require configN.rb so that all
> definitions are done inside the module?
>
> Thanks in advance,
> Daniel.
> --
> Posted via http://www.ruby-forum.com/.
>
>
You can't do this with require. You probably want module_eval

module One
module_eval File.read("config1.rb")
end

module Two
module_eval File.read("config2.rb")
end

def process(config)
puts config.value
end

process One::Configuration
process Two::Configuration

From: Daniel Vartanov on
It works, thanks!

> You can't do this with require. You probably want module_eval
--
Posted via http://www.ruby-forum.com/.