To my mind the following three examples are logically equivalent and ought to generate identical results.
print "Enter your string: "
my_string = gets.chomp
#Example 1
my_string.include? ("j" or "J")
puts "1. Your string includes a j or J."
#Example 2
if
my_string.include? ("j" or "J")
puts "2. Your string includes a j or J."
end
#Example 3
if
my_string.include? ("j") or my_string.include? ("J")
puts "3. Your string includes a j or J."
end
Here are the results with a capital J.
Enter your string: Jack
1. Your string includes a j or J.
3. Your string includes a j or J.
Here are the results with a lower case j.
Enter your string: jack
1. Your string includes a j or J.
2. Your string includes a j or J.
3. Your string includes a j or J.
For reasons I don't understand, only examples 1 and 3 generate identical results. In example 2, by contrast, only the first item in the brackets (the lower case j) is evaluated.
But why? If example 1 works perfectly, why does example 2 fail simply because the "include?" method is nested within an "if/end"?
And if we need to wrap the code in an "if/elsif/end" conditional, is there a way in which to list multiple values to be assessed in an "include?" method without needing to write them out individually as in example 3? This would be tedious - almost "anti-Ruby" - if there were many values to be evaluated!
In other words, is there a means of making example 2 work correctly?