Skip to content

Instantly share code, notes, and snippets.

@rue
Created May 29, 2009 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rue/120196 to your computer and use it in GitHub Desktop.
Save rue/120196 to your computer and use it in GitHub Desktop.
class Class
protected :instance_type
def initialize(sclass=Object)
unless sclass.kind_of?(Class)
raise TypeError, "superclass must be a Class (#{sclass.class} given)"
end
set_superclass sclass
mc = self.metaclass
mc.set_superclass sclass.metaclass
super()
# add class to sclass's subclass list, for ObjectSpace.each_object(Class)
# NOTE: This is non-standard; Ruby does not normally track subclasses
sclass.__send__ :add_subclass, self
sclass.__send__ :inherited, self
end
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment