This one got me today:

feed_bridge_is_valid = !state[:feed] or (state[:feed] and @feed_bridge.valid?)

It turns out that the “=” assignment has a higher precedence than the “or” operator, so if (in the example above) !state[:feed] turns out to be false then feed_bridge_is_valid will be assigned a false value, and the entire expression will return the value of (state[:feed] and @feed_bridge.valid?).

Here’s one solution:

feed_bridge_is_valid = (!state[:feed] or (state[:feed] and @feed_bridge.valid?))

And I think you can also solve the problem by using the “||” version of the “or” operator too.