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)
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)
The following worked perfectly for creating sequentially numbered
lines: as "def" was invoked successively with various arguments:
@indx=0
def disp(s) @index += 1
printf( [snip]
However, "index=0" inside the def, despite subsequent incrementing,
had the dual faults of assigning the same index to every line and
being inaccessible outside the "def".
I had also tried "if !defined?(indx)" somehow, but that was useless
across multiple invocations of "def".
Again, thanks to you both for your responses.
···
On Jul 20, 4:35 pm, Siep Korteling <s.kortel...@gmail.com> wrote:
reuben doetsch wrote:
> 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
(...)
Or replace "indx" with "@indx".
Regards,
Siep