Let's say you have a controller class and you include a module:
class ApplicationController < ActionController::Base
when cu.group_is?(:a) then a_path
when cu.group_is?(:b) then b_path
when cu.group_is?(:c) then c_path
Notice how this method makes a call to method cu. Now in order for cu to
exist, that means the module methods must be copied into
ApplicationController before any of its methods are called by
class DashboardController < ApplicationController
If the module methods were not included prior to default_page being
called in ApplicationController, since default_page calls method cu
defined in the module AuthenticationSystem, it would throw error.
That part is clear. But what is unclear is what's the whole purpose of
base.send :helper_method, :current_user
If, for example, current_user setter/getter are already declared in
@current_user = User.find_by_id(session[:user_id])
alias :cu :current_user
session[:user_id] = new_user ? new_user.id : nil
@current_user = new_user
and thus will be copied into the ApplicationController class, then
what's the point of sending it to the class using base.send when it will
already be copied into the class?
Or is base.send like a contructor method that gets executed before
anything else in the module and therefore when its included in a class,
it acts as consutrcotr of class and gets called prior to any methods of
the class being called?
Thanks for response.