Ruby equivalent of C # internal keyword?

in C # an "inner" class or method can only be called inside the assembly it is in ... I know Ruby does not have "assemblies" or any real package like them (other than gems, but actually actually it's not exactly the same), but I'm wondering if there is a way to limit the location from which a method can be called, like an internal one?

I am updating a little framework and creating a class that has 3 methods on it. I want to be able to call 2 of 3 methods only from my structure and the third one from anywhere. Is this possible in ruby? or am I going to do it wrong and have to create two separate classes? or?

+2


source to share


1 answer


Unfortunately Ruby is a language that is lacking in terms of encapsulation. The capacity there is pretty limited, so no, nothing is equivalent to the C # keyword. Perhaps, in your case, two separate classes would be better, but a clear docstring or special naming scheme could do the same without heavy changes.



Also, you should note that the internal keyword is nothing more than a convenience for library developers. It doesn't really stop anyone from using a method or class that is marked as internal, there is a way to get around this protection through code injection, AOP, etc.

+2


source







All Articles