Created
February 24, 2010 03:50
-
-
Save lodestone/313081 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| class Kozmik | |
| def self.acts_as_frog(species) | |
| (@frog_list ||= []) << species | |
| #self.class.send :attr_accessor, :frog_list | |
| # | |
| # === OR === | |
| # | |
| # class << self | |
| # attr_accessor :frog_list | |
| # end | |
| # | |
| # === OR === | |
| # | |
| # self.class.class_eval do attr_accessor :frog_list; end | |
| # | |
| # ========== | |
| end | |
| def self.inherited(base) | |
| puts base | |
| puts self | |
| self.class.class_eval do | |
| attr_accessor :frog_list | |
| end | |
| end | |
| end | |
| class Toad < Kozmik | |
| acts_as_frog :bufo | |
| acts_as_frog :kermit | |
| #puts 'Toad the weg sproket' | |
| end | |
| class BullFrog < Kozmik | |
| acts_as_frog :tree | |
| acts_as_frog :riparian | |
| #puts 'Bull****' | |
| end | |
| def test_fun_with_metaclasses | |
| assert_equal [:tree, :riparian], BullFrog.frog_list | |
| assert_equal [:bufo, :kermit], Toad.frog_list | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment