title: How to Initialize Class Arrays in Ruby
body: <p>I want to create an empty array as a class instance variable in Ruby. However, my current method does not seem to work. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>class Something 
      @something = []
      def dosomething
          s = 5
          @something &lt;&lt; s
      end
  end
  </code></pre>
  
  <p>When I call the function, it gives me an undefined method traceback.
  However, if I do something similar with class variables, i.e.:</p>
  
  <pre><code>class Something
      @@something = []
      def dosomething
          s = 5
          @@something &lt;&lt; s
      end
  end
  </code></pre>
  
  <p>This works perfectly. </p>
  
  <p>I know I can use the initialize method to actually create an empty list for @something, but is there another way of doing this without using the initialize method? And why does this work for class variables?</p>
  
  <p>EDIT: Fixed typo</p>