Skip to content

Instantly share code, notes, and snippets.

@deepak
Last active December 11, 2015 09:32
Show Gist options
  • Save deepak/e2e201f876c90a74a0ab to your computer and use it in GitHub Desktop.
Save deepak/e2e201f876c90a74a0ab to your computer and use it in GitHub Desktop.
cannot reopen class and modify include to prepend
# If i have a class, which includes a module
# Now i cannot reopen the class and prepend the same module
# ran on ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]
class Base; end
module M1; end
module M2; end
class C1 < Base; end
puts C1.ancestors.inspect # [C1, Base, Object, Kernel, BasicObject]
class C1
include M1
prepend M2
end
puts C1.ancestors.inspect # [M2, C1, M1, Base, Object, Kernel, BasicObject]
class C1
prepend M1
end
# still still same as before
# M1 did not get prepended
puts C1.ancestors.inspect # [M2, C1, M1, Base, Object, Kernel, BasicObject]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment