From: reuben doetsch Date: 2008-07-20T16:06:08+09:00 Subject: Re: Simple program with a simple(?) error -- what's wrong? ------=_Part_47854_22999555.1216537885815 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline The scope of indx is wrong, when you call it outside the function, it is only accesible witin that scope, the outer scope and so you have you do this def foo indx=0 .... end that will then work, you only need to call foo someplace if you want foo to run. You only define it, creating the function does not call it. On Sat, Jul 19, 2008 at 10:39 PM, RichardOnRails < RichardDummyMailbox58407@uscomputergurus.com> wrote: > Hi, > > I put together to exercise simple Ruby constructs. It's posted at > http://www.pastie.org/237288. > > Before I introduced the "indx" variable it worked fine. The statement > incrementing indx in the def causes the error: > undefined method `+' for nil:NilClass (NoMethodError) > > I'm running: > ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32] > > Why doesn't the def use the instance of indx defined before the def? > > Thanks in Advance, > Richard > > ------=_Part_47854_22999555.1216537885815--