Last active
December 14, 2015 09:39
-
-
Save dblack/5066855 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A # top-level A | |
end | |
module M | |
module ClassMethods | |
def create_an_a | |
A.new # top-level A | |
end | |
end | |
module InstanceMethods | |
def do_something | |
end | |
end | |
end | |
class B | |
class A # nested A | |
extend M::ClassMethods | |
include M::InstanceMethods | |
end | |
def go | |
an_a = A.create_an_a # Calling a method on *nested* A that | |
an_a.do_something # happens to return an instance of | |
end # *top-level* A. | |
end | |
B.new.go # unknown method do_something, because the A object you're | |
# calling it on is an instance of top-level A, | |
# not an instance of nested A, and nested A is | |
# the one with the module included. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment