Skip to content

Instantly share code, notes, and snippets.

@lodestone
Created February 24, 2010 03:50
Show Gist options
  • Select an option

  • Save lodestone/313081 to your computer and use it in GitHub Desktop.

Select an option

Save lodestone/313081 to your computer and use it in GitHub Desktop.
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