include private?
Bharat Ruparel
29 posts
|
David, |
Dave Thomas
Administrator
72 posts
|
Bharat: A private method is Ruby is one that cannot be called with a receiver, and therefore can only be called in the context of the current object. include() is a private method of class Module, and therefore can only be called when self is a Module or subclass thereof. |
Bharat Ruparel
29 posts
|
Thanks for the quick reply. I understand what you are saying in the screen cast now. “cat”.say_hello is a “bad” idea since it breaks encapsulation? You mention towards the end that Rails uses this but did not say whether it was a good or a bad thing. Can you comment on it? There is a reason why I am asking this question. I come from a Java background and the Meta Programming is kept to a minimum even though the source code can be quite long. It seems to me that if the only purpose of writing this kind of code is to shorten the total lines of code statistic then it is definitely a bad thing to do. On the other hand, if there is something more concrete to be gained, then it is a good thing. I am asking you if there is a more compelling reason to do this kind of thing in practice besides just being clever? |
Dave Thomas
Administrator
72 posts
|
Bharat: It’s all contextual. When it’s good, it’s good. When it isn’t, it isn’t. Part of the skill of programming is knowing the difference, and that experience comes from trying, making mistakes, and learning. In general, the motivation is never simply to write shorter code. It’s to write more maintainable code—code that’s easier to work with and change. |
4 posts, 2 voices
