Given Hash:
hash = {}
This expression:
hash[:key] ||= :value
Expands to:
hash[:key] || hash[:key] = :value
Ruby's logical operators are a short circuit , which means it hash[:key] = :valuewill only be executed if and only if it hash[:key]is either falseor nil.
If this is something else, only its value will be sufficient to determine the result of a logical disjunction , and the rest of the expression will not be evaluated.
This is fundamentally different from:
hash[:key] = hash[:key] || :value
[]= , , : :value, hash[:key] false, nil, hash[:key] .