D
dkmd_nielsen
I'm new to Ruby (love it!). Below is a method that works just fine.
Passed to it as (i) is a two element array [parm,arg]. The method does
a table lookup on @itBlock (an array of two element arrays), and
replace the tables arg value with the arg value passed (if parm is
found in table). I understand the variable referencing that is going
on.
def loadparm(i)
@itBlock.each_index {|k|
j = @itBlock[k] # for each row
next if j[0] != i[0] # if not correct parm
j[1] = i[1].strip! # replace argument
k = j
break # get out of loop
}
end
What I don't understand is why the following does not work. I would
think the variable referencing would still be in tact. The values parm
and arg match the @itBlock row values entering and exiting the loop.
However, the @itBlock row is not updated.
def loadparm(i)
@itBlock.each {|parm,arg|
next if parm != i[0] # if not correct parm
arg = i[1].strip! # replace argument
break # get out of loop
}
end
Would some explain explain what is happening to the pointers and
variable referencing in the second example? I second question would
be...can I accept i as two arguments, as in "def loadparm(x,y)?
Thanks.
Passed to it as (i) is a two element array [parm,arg]. The method does
a table lookup on @itBlock (an array of two element arrays), and
replace the tables arg value with the arg value passed (if parm is
found in table). I understand the variable referencing that is going
on.
def loadparm(i)
@itBlock.each_index {|k|
j = @itBlock[k] # for each row
next if j[0] != i[0] # if not correct parm
j[1] = i[1].strip! # replace argument
k = j
break # get out of loop
}
end
What I don't understand is why the following does not work. I would
think the variable referencing would still be in tact. The values parm
and arg match the @itBlock row values entering and exiting the loop.
However, the @itBlock row is not updated.
def loadparm(i)
@itBlock.each {|parm,arg|
next if parm != i[0] # if not correct parm
arg = i[1].strip! # replace argument
break # get out of loop
}
end
Would some explain explain what is happening to the pointers and
variable referencing in the second example? I second question would
be...can I accept i as two arguments, as in "def loadparm(x,y)?
Thanks.