Created
January 25, 2011 18:33
-
-
Save rkh/795357 to your computer and use it in GitHub Desktop.
This file contains 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
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] |
This file contains 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
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