Ch Ba wrote:
> The previous returns a nomethoderror
> for "include" in the instance of test.

Use "extend" rather than "include" if you want to add a module to a 
single object, rather than to a class.

I think this does what you want:

module Thing
  def self.extended(obj)
    obj.instance_eval do
      @bar = 5
    end
  end
end

class Foo
  def initialize
    @bar = 0
    @foo = 2
  end
end

class FooBar < Foo
  def initialize(*modules)
    super()
    @bar = 1
    modules.each do |mod|
      extend mod
    end
  end
end

test = FooBar.new(Thing)
p test

If you want to pass a symbol like :thing instead of the actual module 
Thing, then you can use Object.const_get as others have pointed out. Or 
build a hash:

  ALLOWED_MODULES = {
    :thing => Thing,
  }

  ...
    extend ALLOWED_MODULES[mod]
-- 
Posted via http://www.ruby-forum.com/.