Requiring files in a module context

  • Thread starter Daniel Vartanov
  • Start date
D

Daniel Vartanov

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.
 
L

Lee Jarvis

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

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.
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,148
Messages
2,570,838
Members
47,385
Latest member
Joneswilliam01

Latest Threads

Top