From: Sam Duncan Date: 2012-10-09T05:17:43+09:00 Subject: Re: Undefined method `-' for nil On 10/09/2012 09:13 AM, Joz Private wrote: > Hi guys. > > So I've hit a brick wall with a simple piece of code and hope someone > here can shed some light on what's going wrong ... > > *************************************************** > developer_object_array.each do |dev| > if dev.is_solvent? == false > then puts("#{dev.name} is bankrupt.") > dev.bankrupt = true > bank_object_array.each do |bank| > bank.moves_loans(amount) > else puts("#{dev.name} is not bankrupt.") > end > end > ********************************************************* > > I have the above piece of code in a class. Inside this class I create > and array of Bank and Developer objects. When the code gets to > bank.move_loans > I get an "undefined method `-' for nil:NilClass (NoMethodError" error. > > The move_loans method is defined in the Bank class just does some basic > subtraction on the value passed to it. > > I've no idea what the error is, as I've torn through every piece of code > in the classes and can't see anything wrong. > > Any ideas would be great!! Thanks! > Really need to see what the developer objects and bank objects look like, and how/ where the bank_object_array gets populated. Sam