Sibling-only methods

I remember reading a post (or something) about a technique to fake sibling-only methods using modules and interfaces. In short, I want to create class methods that are only available to certain other classes, not globally.

Does anyone know where I can find that?

If you put two classes in a module and make one private to the module, only classes inside the module can use it. Same would hold true for a private interface

BTW I think you are referring to an old Aaron Ballman blog post.

  • Karen

The problem is, one class would have been public but with methods that should only be accessed by a sibling.

I said “would have been” since I’ve not refactored to make this moot, but I’d still like to know.

Well then Protect the methods in the class and make a private interface to the module for those methods that the sibling in the module will be able to see, nothing outside of it will.

I think Aaron called those friend classes.

  • karen

I didn’t realize that a private or protected method could still be used to implement an Interface method. That makes perfect sense.

Thanks Karen.

Aaron’s book, for anyone interested:

http://great-white-software.com/rblibrary/index.php?main_page=product_info&cPath=33&products_id=111