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
Advertisements
Tagged

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: