Search code examples
ruby-on-railsruby

How to find all classes that includes a module


I have a module called Nameable and some models that include this module.

Is there a way to know which models (classes) have included this module?


Solution

  • I figured out how to find at least the name of all classes.

    Module.constants.select { |c| (eval c.to_s).is_a?(Class) && (eval c.to_s).include?(Nameable)}
    

    I'm not sure if it's the best way to do it though.