Reputation: 1
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
Upvotes: 0
Views: 11365
Reputation: 7719
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
Upvotes: 6
Reputation: 27855
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
Upvotes: 3
Reputation: 6682
Use parentheses with those include?
arguments.
if "test".include?("te") || "test".include?("fail")
puts "true"
end
Upvotes: 5
Reputation: 83680
if "test".include?("te") || "test".include?("fail")
puts "true"
end
Upvotes: 1