I have this very simple test code:
s="helloCustomer"
is_contain_customer = s=='helloCustomer' || s.include? 'Customer' ? 'YES' : 'NO'
I got error message Unexpected tSTRING_BEG for the 2nd line in the code.
Why?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In addition to the syntax error (you need parentheses around method args if the syntax is ambiguous), your code is not as clear as it could be.
You’re using the higher precedence of || vs ? : to cause the expression to ultimately return ‘YES’ or ‘NO’
For the sake of readability and maintainability, I suggest that you add parentheses to make the intent clear:
Also, if you’re using Rails or another MVC system, it’d be better to use your View layer to convert the data (the boolean value) to a string.