From: Ross Harvey Date: 2010-12-14T09:57:32+09:00 Subject: Re: String or string Same problem, though. That's the same thing as if (u2 != "...") || true Which, of course, is the same thing as "if true". Did you mean: if u2 != "force" && u2 != "spells" ...perhaps? On Mon, Dec 13, 2010 at 3:27 PM, Garrison Taylor wrote: > When I typed it I wasn't looking at it, it was actually > > u2 = gets.chomp >  If u2 != "force" || "spells" >  Puts "blah" > > Scratch.mit.edu. Go there! > > -gbear605 > > On Dec 13, 2010, at 6:09 PM, Josh Cheek wrote: > >> On Mon, Dec 13, 2010 at 4:53 PM, Garrison Taylor >> wrote: >> >>> I am doing something where I do >>> If "force" || "spells" >>> Puts "blah" >>> >>> >>> >>> When I use it it gives a warning about comparing strings, what's happening >>> and how do I fix it? >>> >>> Scratch.mit.edu. Go there! >>> >>> -gbear605 >>> >> >> || is a boolean method meaning "or". It is concerned with the truthiness and >> falsiness of its parameters. The set of falsy objects is { false , nil }, >> everything else is truthy. That means that strings are truthy, so when you >> say "force" || "spells" it looks at "force", sees it isn't false and it >> isn't nil, and so is considered true. Every time. >> >> So "force" || "spells" will always return "force", a truthy value, to the if >> statement. Thus the if statement will always execute. >> >> if "force" || "spells" >>  puts "blah" >> end >> >> is the same as >> >> if "force" >>  puts "blah" >> end >> >> is the same as >> >> if true >>  puts "blah" >> end >> >> is the same as >> >> puts "blah" >> >> >> >> That is probably not what you wanted, so it warns you of the issue. > >