Evilr does this easily because in ruby, modules and classes are internally almost identical. They are both stored in the Rclass struct. The only differences are their internal type flag and how the super pointer in the Rclass struct is treated.
So converting a class to a module is as simple as modifying the internal flags bitfield and changing the super pointer in the class not to point to the superclass.
Changing a module to a class just requires modifying the flags bitfield and changing the super pointer to point to a given superclass.