title: Object "main" in Ruby
body: <p>I wrote this script to better understand Ruby's <code>self</code>, but I can't really wrap my head around these statements:</p>
  
  <pre><code>def self.test1
    'test1'
  end
  
  def test2
    'test2'
  end
  
  puts test1 #=&gt; 'test1'
  puts test2 #=&gt; 'test2'
  puts self.test1 #=&gt; 'test1'
  puts self.test2 # test1.rb:12:in `&lt;main&gt;': private method `test2' called for main:Object (NoMethodError)
  </code></pre>
  
  <p>If <code>self.test2</code> doesn't work, why does <code>test1</code>? Does it have something to do with the behavior of the <code>main</code> object?</p>
  
  <p>Does it have something to do with singleton objects? I know that in Ruby when you say <code>def foo.bar</code>, you're defining a bar method on a foo object? How does this fact relate to the original question about why <code>self2.test2</code> fails?</p>