Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Convert Classes and Objects to Modules so they can be extended/included.
Ruby C
Failed to load latest commit information.
ext/object2module fixed is_meta_singleton vs rb_is_meta_singleton bug
lib fixed is_meta_singleton vs rb_is_meta_singleton bug
test fixed bug in Object2module where it was including entire inheritance …
README.markdown readme



(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_include and gen_extend methods which are generalizations of the traditional include and extend.

example: gen_include()

Using gen_include we can include a class into another class:

class C
  def hello

class D
  gen_include C
end #=> :hello
D.ancestors #=> [D, C, Object, ...]

example: gen_extend()

gen_extend lets us mix objects into objects:

o =
class << o
  def bye

n =
n.gen_extend o
n.bye #=> :bye

How it works

Object2module removes the check for T_MODULE from rb_include_module() and prevents inclusion of classes above Object (or meta^n(Object) for singleton classes).

Companion Libraries

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

Something went wrong with that request. Please try again.