Skip to content

Instantly share code, notes, and snippets.

@rkh
Created January 25, 2011 18:33
Show Gist options
  • Save rkh/795357 to your computer and use it in GitHub Desktop.
Save rkh/795357 to your computer and use it in GitHub Desktop.
module ClassHook
extend_object Class
def new(sclass = Object, *args)
super(sclass.to_class, *args)
end
end
module ModuleHook
append_features Module
def to_class
return self if self.is_a? Class
mixin = self
Class.new { include mixin }
end
end
class Foo < Comparable
end
p Foo.ancestors # [Foo, #<Class:0xb88>, Comparable, Object, Kernel]
module ClassHook
extend_object Class
def new(sclass = Object, *args)
super(sclass.to_class, *args)
end
end
module ModuleHook
append_features Module
def to_class(superclass = Object)
return self if self.is_a? Class
mixin = self
Class.new(superclass) { include mixin }
end
end
Module.send :alias_method, :<, :to_class
class Foo < Comparable < Enumerable
end
p Foo.ancestors # [Foo, #<Class:0xb88>, Comparable, #<Class:0xb8a>, Enumerable, Object, Kernel]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment