Difference between adding instance methods with Active Concern and a regular ruby module?

时间:2015-10-30 23:12:00

标签: ruby-on-rails ruby activesupport-concern

What is the difference between adding instance methods whith active concern and through the normal ruby def keyword on the module?

module MonsterConcern
  extend ActiveSupport::Concern

  included do
    def engage_rage
    end

    def chew_bones
    end
  end
end

and

module MonsterConcern
  def engage_rage
  end

  def chew_bones
  end
end

1 个答案:

答案 0 :(得分:0)

据我所知,如果你唯一感兴趣的是实例方法没有区别。

ActiveSupport::Concern的优点是能够定义类方法,并更好地处理一些讨厌的模块相互依赖性(与调用included块中的类方法有关)。

您可以在此处阅读更多内容:http://api.rubyonrails.org/classes/ActiveSupport/Concern.html

相关问题