0
votes

Why does this result in a syntax error "syntax error, unexpected keyword_end, expecting $end"?:

if "test".include?"te" || "test".include?"fail"
  puts "true"
end

The following works:

fail = "test".include?"fail"

if "test".include?"te" || fail
  puts "true"
end
4

4 Answers

6
votes

Another solution: replace operator "||" with "or" which has lower precedence so you can leave parentheses omitted:

if "test".include?"te" or "test".include?"fail"
  puts "true"
end
5
votes

Use parentheses with those include? arguments.

if "test".include?("te") || "test".include?("fail")
  puts "true"
end
3
votes

You must use a brace around the 2nd parameter.

if "test".include?("te") || "test".include?("fail")
  puts "true"
end

or

if "test".include? "te" || ("test".include? "fail" )
  puts "true"
end
1
votes
if "test".include?("te") || "test".include?("fail")
  puts "true"
end