This one really gave me a full trip.
x ||= y
actually behaves as
x || (x = y)
x = (x || y)
In short, what this means is that y is assigned to x only if x is falsy. We know that anything which is not false or nil is truthy in Ruby, so in your example, foo (false) is falsy and bar (2) is truthy.
foo ||= bar
is evaluated as
foo || (foo = bar)
Since foo is truthy, foo = bar is not executed, and foo is returned from the statement.
The value of foo, 2, is printed.