Tag Archives: hook

Hook method

module MyMixin
  def self.included(base) #Hook fired when module is included
     base.extend(ClassMethods) #Allows for the addition of modules class methods to the base (includer).
  end

  def kill 
    "killme"
  end

  module ClassMethods 
    def x
      "x()"
    end 
  end
end

class B 
  include MyMixin
end

b = B.x #Modules class meth called
k = B.new
p k.kill #Modules instance meth called
p b
Tagged