(C) John Mair (banisterfiend) 2010
Enables Classes and Objects to be mixed into ancestor chains
Using Object2module you can treat classes and object (their singletons, anyway) as if they were modules and include or extend them into ancestor chains.
Object2module provides the
gen_extend methods which are generalizations of the traditional
gen_include we can include a class into another class:
class C def hello :hello end end class D gen_include C end D.new.hello #=> :hello D.ancestors #=> [D, C, Object, ...]
gen_extend lets us mix objects into objects:
o = Object.new class << o def bye :bye end end n = Object.new n.gen_extend o n.bye #=> :bye
Object2module removes the check for
rb_include_module() and prevents inclusion of classes above Object
(or meta^n(Object) for singleton classes).
Object2module is one of a series of experimental libraries that mess with the internals of Ruby to bring new and interesting functionality to the language, see also:
- Remix - Makes ancestor chains read/write
- Include Complete - Brings in module singleton classes during an include. No more ugly ClassMethods and included() hook hacks.
- Prepend - Prepends modules in front of a class; so method lookup starts with the module
- GenEval - A strange new breed of instance_eval
- LocalEval - instance_eval without changing self
Problems or questions contact me at github