Skip to content

Instantly share code, notes, and snippets.

@davidbkemp
Created May 20, 2012 05:04
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 davidbkemp/2749196 to your computer and use it in GitHub Desktop.
Save davidbkemp/2749196 to your computer and use it in GitHub Desktop.
Use of self.included
module Foo
# Should not really need the check for const_dedined?, but...
FOO = [] unless const_defined?(:FOO)
def self.included(host_class)
FOO << host_class
end
end
class Baa
include Foo
def baa
puts "Baa1"
end
end
class Baa2
include Foo
def baa
puts "Baa2"
end
end
Foo::FOO.each {|clazz| clazz.new.baa}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment