0

Why does calling f() with the following definition report void value expression error while calling g() is OK?

def f(n)
  return n == 0 or n == 1
end

def g(n)
  return (n == 0 or n == 1)
end
sawa
  • 165,429
  • 45
  • 277
  • 381
fstang
  • 5,607
  • 4
  • 25
  • 26
  • 1
    From [the ruby style guide](https://github.com/bbatsov/ruby-style-guide): The `and` and `or` keywords are banned. The minimal added readability is just not worth the high probability of introducing subtle bugs. For boolean expressions, always use `&&` and `||` instead. – Tom Lord May 09 '18 at 09:33
  • 1
    This question is a good example of why using `and` and `or` cause more problems than they're worth. Frankly, I'd rather see those key words just removed from the language. (But that will almost certainly never happen, due to backwards compatibility!) – Tom Lord May 09 '18 at 09:34

0 Answers0