Skip to content

Instantly share code, notes, and snippets.

@mauriciozaffari
Created August 16, 2011 20:56
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 mauriciozaffari/1150156 to your computer and use it in GitHub Desktop.
Save mauriciozaffari/1150156 to your computer and use it in GitHub Desktop.
Keep track of classes including the module
ruby-1.9.2-p180-patched :001 > module Test
ruby-1.9.2-p180-patched :002?> def self.included(base)
ruby-1.9.2-p180-patched :003?> @classes ||= []
ruby-1.9.2-p180-patched :004?> @classes << base
ruby-1.9.2-p180-patched :005?> end
ruby-1.9.2-p180-patched :006?> def self.classes
ruby-1.9.2-p180-patched :007?> @classes
ruby-1.9.2-p180-patched :008?> end
ruby-1.9.2-p180-patched :009?> end
=> nil
ruby-1.9.2-p180-patched :010 > class Hello
ruby-1.9.2-p180-patched :011?> include Test
ruby-1.9.2-p180-patched :012?> end
=> Hello
ruby-1.9.2-p180-patched :013 > Test.classes
=> [Hello]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment