So this is fun - found another thing about Ruby that I find completely screws up a fairly basic principle of object-oriented design.
The whole point of access level control is to explicitly prevent access to certain methods under certain conditions, thereby allowing you to refactor your classes to put small common processes into methods which shouldn't be exposed. In other words, a "private" method should not be accessible by anything other than members of the same class. In Ruby, this is a complete farce. There's literally no reason to mark a method as private.
Let's take this code:
class Greeting def greet puts "Hello!" end private :greet end
One would suspect you cannot access the greet method. WRONG!! Here's 2 things you can do without even breaking a sweat
x = Greeting.new x.send :greet
Even easier ... it's even transparent once you apply it (you can invoke the method as normal):
x = Greeting.new def x.greet super end
And there you have it. Access levels are a joke!
There are no comments for this post.