I can't see a practical difference between the boolean operators AND and OR in a Ruby case conditional.
For example, I want to get the user to input the sentence:
sudo make me a sandwich
And the case conditional starts as follows:
case user_selection when /sudo/ && /sandwich/
However, if the user enters:
make me a sandwich
The condition will be a satisfied.
My way around it in this instance is to re-order the conditions:
case user_selection when /sandwich/ && /sudo/
But that pre-supposes that every time a user thinks to use "sudo" he will include the string "sandwich" in his response. However, this is functionally no different from this:
case user_selection when /sudo/
I looked up boolean operators for Ruby conditionals, but have not found a satisfactory answer.
Case statements evaluate a single variable, and check if it matches the when argument.
ReplyDeleteWhen [expression]
Does not work like an if conditional, executing the block if the expression is true. Instead it works more like an index for matches.
Think...
DeleteIf ( [expression] ==
[possible match] ) then
[possible match] ) then