Ruby ternary - warning: string literal in condition
ruby, ternary-operator
Solution
Without parentheses, ruby is interpreting it as
phrase.last.eql?( "?" ? true : false )
which explains the message "warning: string literal in condition".
To fix this, use parentheses on the parameter:
phrase.last.eql?("?") ? true : false
Of course, in this case using the ternary operator is redundant since this is the same as simply
phrase.last.eql?("?")
Problem
This code works as expected: ``` if phrase.last.eql? "?" ? true : false true else false end ``` but this code using the Ruby ternary operator: ``` phrase.last.eql? "?" ? true : false ``` gives the following error: warning: string literal in condition Do I need to escape the `"?"` somehow?