ruby equivalent of c#'s internal keyword?
in C# an "internal" class or method can only be called from within the assembly that it is located... i know Ruby doesn't have "assemblies" or any kind of real package like them (other than gems, but they aren't really the same thing at all), but I'm wondering 开发者_运维知识库if there is a way for me to limit the location that a method can be called from, similar to internal?
I'm updating a small framework and created a class that has 3 methods on it. I want to be able to call 2 of the 3 methods only from my framework, and the third method from anywhere. Is this possible in ruby? or am I going about this wrong and should be creating two separate classes? or ?
Unfortunately, Ruby is a language that's quite lacking in terms of encapsulation. It's capacity there are quite limited so, no, there isn't anything equivalent to C# internal keyword. Maybe in your case two separate classes would be better, but a clear docstring or a special naming scheme could do the same without heavy modifications.
Also, you must note that the internal keyword is nothing more than convenience for library developers. It doesn't truly prevent someone from using a method or class marked as internal, there's way to circumvent these protection with code injection, AOP, etc.
精彩评论