I am trying to write a function that takes a string and takes desired indices and scrambles the string:
def scramble_string(string, positions)
temp = string
for i in 0..(string.length-1)
temp[i] = string[positions[i]]
end
puts(string)
return temp
end
When I call the above method, the "string" is altered, which you will see in the output of puts
.
Why does this happen since I didn't put string
on the left-hand side of an equation I wouldn't expect it to be altered.