I thought
class ApplicationController < ActionController::Base
include Foo
is to add a “mixin” — so that all methods in the Foo module are treated as methods of the ApplicationController.
But now I see code that is
include Bar
class ApplicationController < ActionController::Base
include Foo
So why is it outside of ApplicationController? How is that different from the more common use of putting it inside of ApplicationController?
Yes,
include Fooinside a class addsFooto that class’s ancestors and thus makes all ofFoo‘s instance methods available to instances of those class.Outside of any class definition
include Foowill addFooto the ancestors ofObject. I.e. it is the same as if you didinclude Fooinside the definition of theObjectclass. The use doing this is that all ofFoo‘s instance methods are now available everywhere.