Quantcast
Channel: Pragmatic Forums | Posts by Bharat Ruparel
Viewing all articles
Browse latest Browse all 25

include private? posted by Bharat Ruparel @ Thu, 26 Jun 2008 20:11:27 +0000

$
0
0

Thanks for the quick reply. I understand what you are saying in the screen cast now.
I am referring to episode 4 – use 3: it seems to me that this kind of use of include as shown in the code snippet below:
module Hello def say_hello puts "hi from #{self.inspect}" end end [ String, Array, Hash ].each do |cls| cls.class_eval { include Hello } end

“cat”.say_hello
[1,2].say_hello
{ 1 => 2 }.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?


Viewing all articles
Browse latest Browse all 25

Trending Articles