Remix

(C) John Mair (banisterfiend) 2010

Ruby modules remixed and remastered

Remix is a library to give you total control over class and module ancestor chains.

Using Remix you can add a module at any point in the chain, remove modules, replace modules, move modules around and otherwise ‘remix’ your modules.

example: temp_include():

Using temp_include we can temporaliy mix in a module for the duration of a block:

module M def hello() :hello end end

String.temp_include(M) do
  puts "test".hello #=> "hello"
end

"test".hello #=> NoMethodError

example: unextend()

Like the Mixico library Remix allows you to unextend (or uninclude) modules from inheritance chains; but also extends this functionality by (optionally) removing nested modules too:

C.ancestors #=> [C, A, B]

o = Object.new
o.extend C
o.singleton_class.ancestors #=> [C, A, B, Object, ...]

# remove entire nested module C by passing true as second parameter
o.unextend C, true

o.singleton_class.ancestors #=> [Object, ...]

Special features

Remix is intelligent enough to manipulate classes as well as modules:

class D < C
  include M
end

D.ancestors #=> [D, M, C]

D.swap_modules C, M

D.ancestors #=> [D, C, M]

It does this by first converting all superclasses to Included Modules before remixing takes place.

How it works

Remix is a C-based extension that directly manipulates the superclass pointers of Included Modules.

Companion Libraries

Remix 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:

Full list of functions

include-based functions:

extend-based functions:

Limitations

Remix does not currently reorder the singleton classes of superclasses to reflect the new position of the class. This functionality is coming soon.

Special Thanks

Asher

Contact

Problems or questions contact me at github

Dedication

For Rue (1977-)