From: Josh Cheek Date: 2010-12-14T08:09:15+09:00 Subject: Re: String or string --001485f92a88c18474049752ca04 Content-Type: text/plain; charset=ISO-8859-1 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. --001485f92a88c18474049752ca04--