title: Difference between @instance_variable and attr_accessor
body: <p>I Just started learning ruby and I don't see the difference between an <code>@instace_variable</code> and an attribute declared using <code>attr_accessor</code>.</p>
  
  <p>What is the difference between the following two classes:</p>
  
  <pre><code>class MyClass  
    @variable1 
  end
  </code></pre>
  
  <p>and</p>
  
  <pre><code>class MyClass
    attr_accessor :variable1
  end
  </code></pre>
  
  <p>I searched lot of tutorials online and everybody uses different notation, Does it have to do anything with the ruby version? I also searched few old threads in StackOverflow </p>
  
  <blockquote>
    <p><a href="https://stackoverflow.com/questions/4370960/what-is-attr-accessor-in-ruby">What is attr_accessor in Ruby?</a> <br>
    <a href="https://stackoverflow.com/questions/2751930/whats-the-difference-between-these-two-ruby-class-initialization-definitions">What&#39;s the Difference Between These Two Ruby Class Initialization Definitions?</a></p>
  </blockquote>
  
  <p>But still I am not able to figure out what is the best way to use.</p>