<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Recent Posts in 'Questions regarding episode 1...' | Pragmatic Forums</title>
    <link>http://forums.pragprog.com/forums/77/topics/575</link>
    <language>en-us</language>
    <ttl>60</ttl>
    <description></description>
    <item>
      <title>Questions regarding episode 1... posted by Daniel Waite @ Tue, 24 Jun 2008 21:32:55 -0000</title>
      <description>&lt;p&gt;Ah, interesting. So the def keyword always wants to make instance-level methods unless told explicitly otherwise.&lt;/p&gt;


	&lt;p&gt;I dig your illustration of where programs get written. Before it was always a black box, now I feel like I&amp;#8217;m bootstrapped into a rocket or something. Fun stuff. :)&lt;/p&gt;</description>
      <pubDate>Tue, 24 Jun 2008 21:32:55 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:77:575:3327</guid>
      <author>Daniel Waite</author>
      <link>http://forums.pragprog.com/forums/77/topics/575</link>
    </item>
    <item>
      <title>Questions regarding episode 1... posted by Dave Thomas @ Sun, 22 Jun 2008 13:38:28 -0000</title>
      <description>&lt;blockquote&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;
  class Dave

    # If self is Dave, why must I explicitly say self?
    #
    def self.meth
    end
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/blockquote&gt;

	&lt;p&gt;Because &lt;code&gt;def meth&lt;/code&gt; (without the self) would declare an instance method. You want to define a method callable on the class.&lt;/p&gt;


	&lt;p&gt;As for the top-level execution environment&amp;#8230; well, at that point you&amp;#8217;re actually inside something that looks like this:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
class Object 
   Object.new.instance_eval do 
     def self.to_s 
       "main" 
     end 

     ## 
     # Your program gets inserted here... 
     ## 

   end 
end 
&lt;/code&gt;&lt;/pre&gt;</description>
      <pubDate>Sun, 22 Jun 2008 13:38:28 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:77:575:3296</guid>
      <author>Dave Thomas</author>
      <link>http://forums.pragprog.com/forums/77/topics/575</link>
    </item>
    <item>
      <title>Questions regarding episode 1... posted by Daniel Waite @ Sun, 22 Jun 2008 08:07:35 -0000</title>
      <description>&lt;p&gt;I wrote this in TextMate first so I&amp;#8217;ll paste it here&amp;#8230;&lt;/p&gt;


&lt;pre&gt;
class Dave

  # If self is Dave, why must I explicitly say self?
  #
  def self.meth
  end

  # If self is Dave, why isn't this the same as saying
  # self.another_meth?
  #
  def another_meth
  end

  # Valid...
  meth

  # Invalid...
  another_meth

end

# If I'm standing in a class definition here,
# why can I call a method not prefixed with self,
# but I can't inside the Dave class definition?
# (as shown above)

def outer_meth
  puts "Hi" 
end

def self.outer_meth_2
  puts "Hi again" 
end

# And why does this work?

outer_meth
outer_meth_2
&lt;/pre&gt;

	&lt;p&gt;I&amp;#8217;ll add that I&amp;#8217;ve never had these questions before; the differences between &amp;#8220;class-level&amp;#8221; and instance-level methods has always made sense to me.&lt;/p&gt;


	&lt;p&gt;But after watching this I suddenly have these questions.&lt;/p&gt;


	&lt;p&gt;I guess everything I&amp;#8217;m asking hinges on my statement about being inside a class definition outside any visible class definition (i.e. where self == main). If I&amp;#8217;m wrong about that then I suppose the answer is, &amp;#8220;because that&amp;#8217;s the way it works&amp;#8221;.&lt;/p&gt;</description>
      <pubDate>Sun, 22 Jun 2008 08:07:35 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:77:575:3295</guid>
      <author>Daniel Waite</author>
      <link>http://forums.pragprog.com/forums/77/topics/575</link>
    </item>
  </channel>
</rss>
