title: Creating an array within a Ruby object class
body: <p>I just want to write a Ruby script (no rails) with a class that contains an array of ids. Here is my original class: </p>
  
  <pre><code># define a "Person" class to represent the three expected columns
  class Person &lt;
  
    # a Person has a first name, last name, and city
    Struct.new(:first_name, :last_name, :city)
  
    # a method to print out a csv record for the current Person.
    # note that you can easily re-arrange columns here, if desired.
    # also note that this method compensates for blank fields.
    def print_csv_record
      last_name.length==0 ? printf(",") : printf("\"%s\",", last_name)
      first_name.length==0 ? printf(",") : printf("\"%s\",", first_name)
      city.length==0 ? printf("") : printf("\"%s\"", city)
      printf("\n")
    end
  end
  </code></pre>
  
  <p>Now I would like to add an array called ids to the class, can I include it in the Struct.new statement like Struct.new(:first_name, :last_name, :city, :ids = Array.new) or create an instance array variable or any define separate methods or something else?</p>
  
  <p>I would like to then be able to do things like:</p>
  
  <pre><code>p = Person.new
  p.last_name = "Jim"
  p.first_name = "Plucket"
  p.city = "San Diego"
  
  #now add things to the array in the object
  p.ids.push("1")
  p.ids.push("55")
  </code></pre>
  
  <p>and iterate over the array</p>
  
  <pre><code>p.ids.each do |i|
    puts i
  end
  </code></pre>