title: Is there a limit to the number of instances a class can have in Ruby?
body: <p>In Ruby, I'm parsing a CSV file and storing the values into a class (each 'column' in the csv corresponds to an attribute of my class, Expense). My CSV has 15.000 rows. But after I go through all the lines, I only have 260 objects of the Expense class, instead of 15.000, which is the number of rows. If I parse a CSV with 100 rows, it works fine, it creates 100 objects of the Expense Class. But up from 150 rows it starts to create issues - 150 rows returns me 36 instances of the class Expense, and 15.000 returns 260. I don't see a logic, it is like at some point it resets the number of instances of my class and starts counting again.</p>
  
  <p>Is there a limit to the number of instances a class can have in Ruby?</p>
  
  <p>This is not a program, and I'm a real begginer. I'm just going a through a CSV, doing some validation on the data, and then returning to a CSV. So I was looking for way in which I didn't need to store the values in a temp file.</p>
  
  <p>Thanks</p>
  
  <p>Code:</p>
  
  <pre><code>class Expense
      attr_accessor :var1, :var2, :var3
      def initialize(var1,var2,var3)
          @var1 = var1
          @var2 = var2
          @var3 = var3
      end
      def self.count
          ObjectSpace.each_object(self).to_a.count
      end
  end
  
  old_file = File.read("C:/Folder/OldFile.csv")
  new_file = File.new("C:/Folder/NewFile.csv", "w")
  puts "Number of rows in input file: #{old_file.count("\n")}"
  puts "Number of Expense objects stored before procedure: #{Expense.count}"
  
  #loop through the rows and store each column as an attribute of the class
  old_file.each_line do |line|
      #save each column of the row as an element of the array
      attr_ay = []
      line.chomp.each_line(';') do |att| 
          attr_ay.push(att.chomp(";"))
      end
      #loops through each attribute and assigns the corresponding value of the array
      i=0
      expense = Expense.new("","","")
      expense.instance_variables.each do |att|
          expense.instance_variable_set(att,attr_ay[i])
          new_file.print(expense.instance_variable_get(att)+";")
          i = i + 1
      end
      #jump to the next line in new file 
      new_file.print "\n"
  end
  new_file.close
  
  #compare number of rows
  new_file = File.read("C:/Folder/NewFile.csv")
  puts "Number of rows in output file: #{new_file.count("\n")}"
  puts "Number of Expense objects stored after procedure: #{Expense.count}"
  
  #Result:
  #Number of rows in input file: 15031
  #Number of Expense objects stored before procedure: 0
  #Number of rows in output file: 15031
  #Number of Expense objects stored after procedure: 57
  </code></pre>