Skip to content

Instantly share code, notes, and snippets.

@simplay
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simplay/a02def6d1fcb24ffb72b to your computer and use it in GitHub Desktop.
Save simplay/a02def6d1fcb24ffb72b to your computer and use it in GitHub Desktop.
# 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