Last active
August 29, 2015 14:17
-
-
Save simplay/a02def6d1fcb24ffb72b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add a method that allows an object to add dyn. new instance methods. | |
module A | |
klass.instance_eval do | |
send(:attr_accessor, :observers) | |
instance_variable_set("@#{:observers}", []) | |
end | |
end | |
# including this object prepends a class' initializer | |
module B | |
module Initializer | |
def initialize | |
@observers = [] | |
super | |
end | |
end | |
def self.included(klass) | |
klass.send :prepend, Initializer | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment