views:

54

answers:

2

I have some modules in an array. All the modules define a method called "process", and I'd like to call each of these process methods in sequence. The code I have looks something like this(assume the modules are all defined inside the Mod class):

modules.each do |mod|
  extend Mod.const_get(mod)
  process(data)
end

This works fine for the first time, but the method doesn't get overwritten after the first pass of the loop. I've tried adding undef process as the last line inside the each block but that didn't work.

Is there any way I can do this?

+1  A: 

is making the 'process' method into a module-method an option (by defining it def self.process)?

If so, sending the method 'process' directly to the returned constant would work:

modules.each do |mod|
  Mod.const_get(mod).send(:process, data)
end

EDIT Come to think of it, why not call the method directly?

  Mod.const_get(mod).process(data)
btelles
+1  A: 

modules can only be included into an inheritance chain once.

Also, what are you doing is really weird, you should think about redesigning your system.

banister