title: Ruby creating instance variables outside a class
body: <p>What does it mean to create an instance variable, say <code>@foo</code> in a file outside any class definition. Say there is a file, test.rb and the entire contents of the file are given below.</p>
  
  <pre><code># test.rb
  @foo = "bar"
  puts @foo
  </code></pre>
  
  <p>It prints <code>"bar"</code>, but is this an instance variable in some sort of wrapping class?</p>
  
  <p>Testing using two files indicates that there is a <code>main</code> object that everything is wrapped inside. Is this understanding correct?</p>
  
  <p><em>Contents of a.rb</em></p>
  
  <pre><code>@me = self
  @a = "from-a"
  </code></pre>
  
  <p><em>Contents of b.rb</em></p>
  
  <pre><code>require "./a"
  
  @b = "from-b"
  puts @me == self # true (self refers to the same object)
  puts self.class  # Object
  puts self.instance_variables # [@a, @b, @me]
  </code></pre>