compound_assignment
➕ Compound Assignment Operators
Ruby lets you combine an operation and assignment in one step using operators like +=
, -=
, *=
, and /=
. This makes your code shorter and more expressive when updating numeric variables.
score = 10
score += 5 # score is now 15
score -= 3 # score is now 12
score *= 2 # score is now 24