The InstanceMethods module inside ActiveSupport::Concern will be no longer included automatically

原创文章,转载请注明来源并保留原文链接

The InstanceMethods module inside ActiveSupport::Concern will be no longer included automatically. Please define instance methods directly in …

今天在一个Rails3.2的项目里发现了这个deprecated,去查看了一下源码,大家可以比较一下:

对比了,发现只是少了这么一句:

base.send :include, const_get("InstanceMethods")

不需要再定义InstanceMethods Module了,直接定义这些方法就行了。#Commit

old

module M
  extend ActiveSupport::Concern

  module ClassMethods
    ...
  end

  module InstanceMethods
    def some_instance_method
      ...
    end
  end
end

new

module M
  extend ActiveSupport::Concern

  module ClassMethods
    ...
  end
 
  # directly define method
  def some_instance_method
    ...
  end

end

Why?

ruby的include行为就是引入instance method,用InstanceMethods确实有点多此一举,不过我想老的版本引入InstanceMethods应该是为了和ClassMethods对应。

One thought on “The InstanceMethods module inside ActiveSupport::Concern will be no longer included automatically

  1. Pingback: about append_features method | Zires

Leave a Reply

Your email address will not be published. Required fields are marked *