title: ruby/rails: How to determine if module is included?
body: <p>Expanding on my question here (<a href="https://stackoverflow.com/questions/28575328/ruby-rails-extending-or-including-other-modules">ruby/rails: extending or including other modules</a>), using my existing solution, what's the best way to determine if my module is included? </p>
  
  <p>What I did for now was I defined instance methods on each module so when they get included a method would be available, and then I just added a catcher (<code>method_missing()</code>) to the parent module so I can catch if they are not included. My solution code looks like:</p>
  
  <pre><code>module Features
    FEATURES = [Running, Walking]
  
    # include Features::Running
    FEATURES.each do |feature|
      include feature
    end
  
    module ClassMethods
      # include Features::Running::ClassMethods
      FEATURES.each do |feature|
        include feature::ClassMethods
      end
    end
  
    module InstanceMethods
      def method_missing(meth)
        # Catch feature checks that are not included in models to return false
        if meth[-1] == '?' &amp;&amp; meth.to_s =~ /can_(\w+)\z?/
          false
        else
          # You *must* call super if you don't handle the method,
          # otherwise you'll mess up Ruby's method lookup
          super
        end
      end
    end
  
    def self.included(base)
      base.send :extend, ClassMethods
      base.send :include, InstanceMethods
    end
  end
  
  # lib/features/running.rb
  module Features::Running
    module ClassMethods
      def can_run
        ...
  
        # Define a method to have model know a way they have that feature
        define_method(:can_run?) { true }
      end
    end
  end
  
  # lib/features/walking.rb
  module Features::Walking
    module ClassMethods
      def can_walk
        ...
  
        # Define a method to have model know a way they have that feature
        define_method(:can_walk?) { true }
      end
    end
  end
  </code></pre>
  
  <p>So in my models I have:</p>
  
  <pre><code># Sample models
  class Man &lt; ActiveRecord::Base
    # Include features modules
    include Features
  
    # Define what man can do
    can_walk
    can_run
  end
  
  class Car &lt; ActiveRecord::Base
    # Include features modules
    include Features
  
    # Define what man can do
    can_run
  end
  </code></pre>
  
  <p>And then I can</p>
  
  <pre><code>Man.new.can_walk?
  # =&gt; true
  Car.new.can_run?
  # =&gt; true
  Car.new.can_walk? # method_missing catches this
  # =&gt; false
  </code></pre>
  
  <p>Did I write this correctly? Or is there a better way?</p>