From: Daniel Harple Date: 2006-06-06T05:16:06+09:00 Subject: Re: Object Troubles - undefined method `+' On Jun 5, 2006, at 10:00 PM, Paul D. Kraus wrote: > When i run the below program I get this error... > ./parse.rb:14:in `incndainvoice': undefined method `+' for > nil:NilClass > (NoMethodError) > from ./parse.rb:31 > from ./parse.rb:20 > > def increment_invoice > invoices = invoices + 1 > end > def increment_ndainvoice > ndainvoice = ndainvoice + 1 > end You are trying to set local variables. Instance variables are prefixed with @. If you were trying to call your attr_writer method, you need to prefix it with self: self.invoices += 1 Here is a more idiomatic way of writing what you would like: class Customer attr_accessor :invoices, :ndainvoices def initialize @invoices = 0 @ndainvoices = 0 end end customers = Hash.new { |h, k| h[k] = Customer.new } IO.foreach('NdaInvoiceCount.txt') do |line| (customer_code, ship_method, customer_name) = line.chomp.split('|') customers[customer_code].invoices += 1 customers[ customer_code ].ndainvoices += 1 if ship_method == 'SAVGRD' end -- Daniel