Skip to content

Instantly share code, notes, and snippets.

/example.rb Secret

Created September 24, 2015 01:39
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 anonymous/020dc114301d9dcb4f53 to your computer and use it in GitHub Desktop.
Save anonymous/020dc114301d9dcb4f53 to your computer and use it in GitHub Desktop.
module TestParent
class Library
def name
"Oxford"
end
end
class Book
def library
Library.new
end
end
end
module Child
class Library < TestParent::Library
def name
"Child Library"
end
end
class Book < TestParent::Book
# any way to avoid having to recreate the method to reset the class scope?
def library
Library.new
end
end
end
@mwlang
Copy link

mwlang commented Sep 24, 2015

module TestParent
  module SharedMethods
    def library
      Library.new
    end  
  end

  class Library
    def name
      "Oxford"
    end  
  end  

  class Book
    include SharedMethods
  end
end  

module Child
  class Library < TestParent::Library
    def name
      "Child Library"
    end  
  end

  class Book < TestParent::Book
    include TestParent::SharedMethods
  end  
end  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment