Ruby operator or

  • Difference of || and or

    In short, they have different priorities. The priority of or is even lower than =.

    Forgetting this can easily cause problems.

from = "some random string"
to = "AAA"

from[/random/] = to or "DEFAULT"
# actually means
(from[/random/] = to) or "DEFAULT"
# and never replace matched part with "DEFAULT"

# one should use
from[/random/] = to || "DEFAULT"

Reference: this SO answer