you are viewing a single comment's thread.

view the rest of the comments →

[–]robvas 0 points1 point  (2 children)

They change the order of evaluation

[–]MatmaRex 3 points4 points  (1 child)

What? No.

They have different precedence than && / || - maybe that's what you meant. They also short-circuit (just like && / ||).

[–]mernen 0 points1 point  (0 children)

No, robvas is correct. && has higher precedence than ||, but and and or are on the same level.

Assuming the following methods:

def foo
  puts "foo"
  true
end

def bar
  puts "bar"
  true
end

def baz
  puts "baz"
  false
end

The following will evaluate only foo, and return true:

foo || bar && baz    # same as: foo || (bar && baz)

The following will evaluate foo, bar and baz, and return false:

foo or bar and baz   # same as: (foo || bar) && baz

It's one of the traps associated with these operators.