I’m using Ruby on Rails, and I want to know how to include a module, from modules that have the same name.
So, I have a ActiveRecord model called Course
it needs to include CourseModuleFactory depending on the course.level
There are 2 CourseModuleFactory modules both with the same name but in different folders.
So I need code something like this:
after_initialize :course_module_factory_level
def course_module_factory_level
if self.level == "A"
self.class.send(:include, CourseModuleFactory ) #from folder A
else
self.class.send(:include, CourseModuleFactory ) #from folder B
end
end
This code would be in the Course model
Without questioning your implementation, maybe you can use this:
Maybe you can try to find out a better design, like renaming these modules differently and avoid having to redefine the same modules again and again