What does #self.included(base) do in Ruby on Rails' Restful Authentication?

后端 未结 5 1944
离开以前
离开以前 2021-01-30 03:50

I thought we would do

helper_method :current_user, :logged_in?, :authorized?

to make these controller methods available for use as helper metho

5条回答
  •  无人共我
    2021-01-30 04:49

    As it is the first result when searching Google for "self.included(base)" I will try to give a small example on how it works. I don't know how much it differs from the restful-authentication-approach.

    It is basically used to make methods from one module available in another module.

    module One
      def hello
        puts 'hello from module One'
      end
    end
    
    module Two
      def self.included(base)
        base.class_eval do
          include One
        end
      end
    end
    
    class ExampleClass
      include Two
    end
    
    ExampleClass.new.hello # => hello from module One
    

提交回复
热议问题