In Rails, variables seem to be linked, ie if if you make a = b, if you change b, you change a as well. Furthermore, if you change a, you also change b.
I come from a raw programing background (FORTRAN and C: languages aerospace is still tethered to), so this linking of variables is new to me. Furthermore, I it has given me some trouble, so I am looking for a way to control it.
I would like to be able to define a variable as a flashed constant value (or array of values), and until I redefine that one specifically, have it remain constant. More specifically, if I do:
a = b
And then I want to redefine
b = q
I would want a to retain the original b value (call it b') while the new b has the value q.
a = b'
b = q
a = b' != b = q
Look at the script below from rails console to further illustrate the aforementioned variable linking. You can tell that the two variables are interdependent: you cannot change one without changing the other. Any help controlling this phenomenon, or simply references to where I can learn more about it, would be more that appreciated.
system :004 > b = []
=> []
system :005 > b = [123,456]
=> [123, 456]
system :006 > a = b
=> [123, 456]
system :007 > a
=> [123, 456]
system :008 > b
=> [123, 456]
system :009 > b[0]
=> 123
system :010 > b[0]=789
=> 789
system :011 > a
=> [789, 456]
system :012 > b
=> [789, 456]
system :013 > a[0] = 0
=> 0
system :014 > a
=> [0, 456]
system :015 > b
=> [0, 456]
system :016 >