ActiveRecord :: Base使用ClassMethods模块扩展

时间:2015-03-14 16:02:04

标签: ruby-on-rails

我在rails console中有这样的代码:

module Taggable
  extend ActiveSupport::Concern
    module ClassMethods
      def taggable?
        false
      end
    end
end
  

当我跑步时:ActiveRecord::Base.send :include, Taggable。我看到这个方法可以标记吗?将成为singleton_class的instance_methods:ActiveRecord::Base.singleton_class.instance_methods.include? :taggable? # => true

     

但是当我跑ActiveRecord::Base.extend Taggable时。我不知道这个方法可以标记在哪里?在? ActiveRecord::Base.singleton_class.methods.include? :taggable? # => false

请帮我理解。

0 个答案:

没有答案