Skip to content

Instantly share code, notes, and snippets.

Created March 25, 2015 16:40
Show Gist options
  • Save anonymous/3f511a93f4f1d5e79a7f to your computer and use it in GitHub Desktop.
Save anonymous/3f511a93f4f1d5e79a7f to your computer and use it in GitHub Desktop.
duplicate module mix-in depending on order
module M
end
class A
end
class B < A
end
b = B.new
class << b
include M
end
class B < A
include M
end
class << b
p ancestors
end
#[#<Class:#<B:0x007fb7ea8355c8>>, M, B, M, A, Object, Kernel, BasicObject]
#but if class B < A; include M; end before class << b; include M; end
#[#<Class:#<B:0x007ff6e2051438>>, B, M, A, Object, Kernel, BasicObject]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment