Topic: Listing included modules of a class instance.

Howdy all,

I am strugglign with something which I am sure should be simple but cannot seem to find a good answer for.

Question, comments and code are in the following code block

# Given the following modules

module Processing
  module One
    def processor
      Processing::One
    end
  end

  module Two
    def processor
      Processing::Two
    end
  end
end

# And the following class that extends itself with modules at runtime based on certain criteria.

class Job
  def extend_with_module(mod)
    case mod
      when 1 then extend Processing::One
      when 2 then extend Processing::Two
    end
  end
end

j1 = Job.new
j1.extend_with_module(1)
j1.processor
=> Processing::One

# I am looking for a method like the following

j1.some_method_that_returns_all_extended_modules_that_this_instance_of_job_is_using_in_an_array
=> [Processing::One]

j2 = Job.new
j2.extend_with_module(2)
j2.processor
=> Processing::Two

j2.some_method_that_returns_all_extended_modules_that_this_instance_of_job_is_using_in_an_array
=> [Processing::Two]

# So that I can get rid of my explicit "processor" method hack and use something much nicer and preferably built-in to the language 

j3 = Job.new
j3.extend_with_module(1)
j3.extend_with_module(2)
j3.some_method_that_returns_all_extended_modules_that_this_instance_of_job_is_using_in_an_array
=> [Processing::One, Processing::Two]

I am sure this must exist somewhere.

Note that I cannot use something like j1.class.included_modules because that doesn't work for modules included at runtime in a particular instance.

I cannot find anything in the class or module docs. Anyone got an ideas?