新手问题 Ruby class mixin 一个模块能否有些函数成为类函数,有些函数成为实例方法

lilijreey · October 28, 2016 · Last by rikiwong replied at October 28, 2016 · 2075 hits

我需要 mixin 一个模块,但是模块中的一些函数成为类函数,一些函数成为实例方法. 请问如何做到

Ruby Pattern: Extend through Include

http://www.dan-manges.com/blog/27

module Module
  module ClassMethods

  end

  module InstanceMethods

  end

  def self.included(receiver)
    receiver.extend         ClassMethods
    receiver.send :include, InstanceMethods
  end
end
You need to Sign in before reply, if you don't have an account, please Sign up first.