<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Recent Posts in 'include private?' | Pragmatic Forums</title>
    <link>http://fora.pragprog.com/forums/77/topics/593</link>
    <language>en-us</language>
    <ttl>60</ttl>
    <description></description>
    <item>
      <title>include private? posted by Dave Thomas @ Fri, 27 Jun 2008 04:33:39 -0000</title>
      <description>&lt;p&gt;Bharat:&lt;/p&gt;


	&lt;p&gt;It&amp;#8217;s all contextual. When it&amp;#8217;s good, it&amp;#8217;s good. When it isn&amp;#8217;t, it isn&amp;#8217;t. Part of the skill of programming is knowing the difference, and that experience comes from trying, making mistakes, and learning.&lt;/p&gt;


	&lt;p&gt;In general, the motivation is never simply to write shorter code. It&amp;#8217;s to write more maintainable code&#8212;code that&amp;#8217;s easier to work with and change.&lt;/p&gt;</description>
      <pubDate>Fri, 27 Jun 2008 04:33:39 -0000</pubDate>
      <guid isPermaLink="false">fora.pragprog.com:77:593:3374</guid>
      <author>Dave Thomas</author>
      <link>http://fora.pragprog.com/forums/77/topics/593</link>
    </item>
    <item>
      <title>include private? posted by Bharat Ruparel @ Thu, 26 Jun 2008 20:11:27 -0000</title>
      <description>&lt;p&gt;Thanks for the quick reply.  I understand what you are saying in the screen cast now.&lt;br /&gt;I am referring to episode 4 &amp;#8211; use 3: it seems to me that this kind of use of include as shown in the code snippet below:&lt;br /&gt;&lt;code&gt;
module Hello
  def say_hello
    puts "hi from #{self.inspect}" 
  end
end

[ String, Array, Hash ].each do |cls|
  cls.class_eval { include Hello }
end
&lt;/code&gt;&lt;/p&gt;


	&lt;p&gt;&amp;#8220;cat&amp;#8221;.say_hello&lt;br /&gt;[1,2].say_hello&lt;br /&gt;{ 1 =&amp;gt; 2 }.say_hello&lt;/p&gt;


	&lt;p&gt;is a &amp;#8220;bad&amp;#8221; 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?&lt;/p&gt;


	&lt;p&gt;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?&lt;/p&gt;</description>
      <pubDate>Thu, 26 Jun 2008 20:11:27 -0000</pubDate>
      <guid isPermaLink="false">fora.pragprog.com:77:593:3368</guid>
      <author>Bharat Ruparel</author>
      <link>http://fora.pragprog.com/forums/77/topics/593</link>
    </item>
    <item>
      <title>include private? posted by Dave Thomas @ Thu, 26 Jun 2008 03:08:42 -0000</title>
      <description>&lt;p&gt;Bharat:&lt;/p&gt;


	&lt;p&gt;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.&lt;/p&gt;</description>
      <pubDate>Thu, 26 Jun 2008 03:08:42 -0000</pubDate>
      <guid isPermaLink="false">fora.pragprog.com:77:593:3353</guid>
      <author>Dave Thomas</author>
      <link>http://fora.pragprog.com/forums/77/topics/593</link>
    </item>
    <item>
      <title>include private? posted by Bharat Ruparel @ Wed, 25 Jun 2008 22:23:35 -0000</title>
      <description>&lt;p&gt;David,&lt;br /&gt;You keep saying that include is a private method throughout the screencssts (specifically episode 4 towards the end in the class_eval section).  May be it is obvious, but I don&amp;#8217;t get it.  How can include be a private method and be used inside a class or module or even be called from outside?  I am not talking about the class_eval {include .. } but include in general.  Perhaps an example snippet will explain it?&lt;br /&gt;Regards,&lt;br /&gt;Bharat&lt;/p&gt;</description>
      <pubDate>Wed, 25 Jun 2008 22:23:35 -0000</pubDate>
      <guid isPermaLink="false">fora.pragprog.com:77:593:3347</guid>
      <author>Bharat Ruparel</author>
      <link>http://fora.pragprog.com/forums/77/topics/593</link>
    </item>
  </channel>
</rss>
