I am not sure how this variable called origString is changing value in my loop
def scramble_string(string, positions)
i = 0
origString = string
puts origString
newString = string
while i < string.length
newString[i] = origString[positions[i]]
i = i + 1
end
puts origString
return newString
end
for example if I run scramble_string("abcd", [3, 1, 2, 0]) origString changes from "abcd" in the first "puts" to "dbcd" in the second one. How am I changing the value of origString if I am only declaring it once?
orig_string, no upper-case letters, as case has significant meaning in Ruby.[]=message or theupcase!message.x = yboth object_ids are same, If we change entire value ofx = 'pest', object_ids will change completely. If we check before changing value object_ids ofx[0]andy[0]are different. . But changing a single value inx(i,ex[0]) reflects in original stringy, HOW?