Skip to content

Instantly share code, notes, and snippets.

@GBH
Created November 17, 2014 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GBH/a0c6e7ec555881242f61 to your computer and use it in GitHub Desktop.
Save GBH/a0c6e7ec555881242f61 to your computer and use it in GitHub Desktop.
Ruby ancestor chain fun
module Foo
def hello
puts 'foo'
end
end
module Bar
def hello
puts 'bar'
end
end
module Baz
def hello
puts 'baz'
end
end
class Parent
include Foo
end
class Child < Parent
end
c = Child.new
c.hello # getting 'foo'
Parent.send(:include, Bar)
c = Child.new
c.hello # getting 'bar'
Parent.send(:include, Baz)
c = Child.new
c.hello # getting 'baz'
Parent.send(:include, Foo)
c = Child.new
c.hello # I want 'foo' back
puts Child.ancestors.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment