1 class Module
2
3
4
5
6 def Module.AddAutomaticMixins
7 ObjectSpace.each_object(Class) do |c|
8 ObjectSpace.each_object(Module) do | mod |
9 mod.add_automatic_mixin( c)
10 end
11 end
12 end
13
14 protected
15 def add_automatic_mixin( other)
16
17 other.class_eval "include #{self}" if( @mix_in_when && other.instance_eval( &@mix_in_when))
18 end
19
20 private
21
22
23
24 def mix_in_when( &predicate) @mix_in_when = predicate; end
25 end
26
27
28 module Comparable
29 mix_in_when { method_defined? :<=> }
30 end
31 module Enumerable
32 mix_in_when { method_defined? :each }
33 end