Regarding attr_accessor and def initialize
<p>I want to add school names to array using attr_accessor.</p>

<p>My question is what 'def initialize()' is doing in this case</p>

<p>so that I can store data by using</p>

<p>v1.school_name[0] = "myschoolname"</p>

<p>If I omit the  initialize() function I get the error</p>

<pre><code>class StoreData

   attr_accessor :school_name
   def initialize
      @school_name = []
   end
end


v1 = Store_data.new 
v1.school_name[0] = "myschoolname"
print v1.school_name[0] 
v1.school_name[1] = "myschoolnamehighschool"
print v1.school_name
</code></pre>