On May 8, 7:15 pm, globalrev [email protected] wrote:
when changing phrase this will change temp as well and even
sentence! makes no sense and very surprising. how do i do what i want
so basically ami messing with pointers here or what?
Essentially, yes, though I believe they are more commonly called
references (and not in that C++ sort of way).
When you do the assignment, phrase = temp, you are simply making
the 0th item of the phrase array refer to the same object that the 1st
item of temp refers.
You need to throw in a
dup call (duplicate) where appropriate. If
you want temp and phrase to be distinct from sentence, then change
those assignments to:
temp = sentence.dup
phrase = sentence.dup
If you wanted only phrase to be distinct from temp, then:
phrase = temp.dup