Skip to content

Instantly share code, notes, and snippets.

@patmaddox
Created April 23, 2009 17:36
Show Gist options
  • Save patmaddox/100630 to your computer and use it in GitHub Desktop.
Save patmaddox/100630 to your computer and use it in GitHub Desktop.
# The goal is to make classes who include Foo also get the methods
# from Bar, but after Foo has already been included
module Foo
def foo; end
end
class FooBar
include Foo
end
module Bar
def bar; end
def self.append_features(other)
ObjectSpace.each_object(Class) do |klass|
klass.send(:include, self) if klass < other
end
super
end
end
module Foo
include Bar
end
FooBar.new.foo # => nil
FooBar.new.bar # => nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment