From: dima Date: 2007-02-14T06:20:06+09:00 Subject: Re: quick newbie true/false/nil question On Feb 13, 9:39 pm, Drew Olson wrote: > Jason Mayer wrote: > > I ran across this line of code today, and it doesn't make sense to me. > > > if ((klass = CommDispatcher.check_hash(path)) == nil) > > I don't know anything about CommDispatcher, but I'd assume you could > rewrite the above code like so: > > if (!CommDispatcher.check_hash(path)) > > The code above seems like a pretty bad code example. > > -Drew > > -- > Posted viahttp://www.ruby-forum.com/. The above code is certainly not a nice-looking one but that was not the question. I suppose that the puzzling part was that the variable klass will be assigned with return value from CommDispatcher.check_hash(path) and that that value could be nil. It is true, if we presume that it is a possible return value from CommDispatcher.check_hash method. The assignment inside the if condition is not a good but it is a common construction especially if you come form C++ world. Ruby has far more interesting constructions but it all depends on a context and mostly on programming style. Generally this assignment inside the if condition should be avoided. Dima