I was bitten a couple of times, forgetting that x = yin Ruby, x makes a reference to the same object as y; I'm too used to the language, which means, in the Ruby, x = y.dup. Forgetting it, I inadvertently change yit when I think itโs safe on the right side of the assignment.
I see that it would be wise to avoid simple appointments for x = yno particular reason, but the same thing can be hidden in other places, such as
name = (person.last_name.blank? ? 'unknown' : person.last_name)
where later name << titlewill actually change person.last_name, not just the name.
If this happened to you, how did you learn to avoid this? Are there certain red flags or patterns to search for? Are you looking with suspicion at every task you do? Do you use a .duplot? I donโt know if using Ruby will be second nature to me, so any helpful hints would be welcome.
source
share