Require two identically named classes in ruby
In my rails application I connect to another ruby application foo that has a class Database in its folder /classes/database.rb and to another application bar that has another class Databse in its folder /classes/database.rb
In that application I have to put the requires in the application controller. That is done by the following code
$: << "C:\foo\
require "plug_in_foo.rb"
in th开发者_JS百科e plug_in_foo.rb there are the requires of the foo project, i.e.
require "/classes/database.rb"
as in the foo project so for the bar project
$: << "C:\bar\
require "plug_in_bar.rb"
and in the plug_in_bar.rb there are the requires of the bar project, i.e.
require "/classes/database.rb"
The Database class in the bar project has its own module wrapped around it but when I try to access the class by BaRModule::Datbase.new it is recognized as an unitialized constant so I think that the require does not work.
Can someone help me with this? Is there a workaround for this?
You can require the absolute paths to the different database files.
(You might also check, if you really need to add all this stuff to your load path)
you should include both of your module in your class like include BaRModule
精彩评论