From: Ben Brightwell Date: 2008-07-29T13:55:08+09:00 Subject: Re: and and or in case Pe単a, The way I see it (and also the way I practice it today) is to always always always use "&&" or "||" over "and" or "or", respectively. The words "and" and "or" are lower in the order of operators than the symbols "&&" and "||". This is intentional for beginner programmers to be able to "read" the code rather than work out the logic of the code. Take this for an example: When using the symbolic operator "||", ruby sees what you write like this: case (when (1==1 || 2==2)) # good "when" keyword and good expression to satisfy it puts "ok" end This is good syntax, and gives the "when" keyword what it is looking for, an expression. When using the word operator "or", ruby sees it like this: case (when 1==1) or (2==2) # good "when" keyword, expression, but then additional "or" keyword puts "ok" end While this reads ok in language, it doesn't quite work for ruby. Because the word "or" gets tried lower in the order of operators, it concludes the "when" keyword with a satisfactory expression, 1==1. Now the "case" keyword is satisfied with a proper "when" keyword. Ruby throws up its red flag when it sees something else past the good expression. To ruby this would be likewise -wrong- to do: case (when (1==1 || 2==2)) or (3==3) puts "ok" end It's all good until the additional "or" keyword. Just remember that ruby sees the "&&"/"||" and "and"/"or" as completely different operators. -- Posted via http://www.ruby-forum.com/.