From: Rick DeNatale Date: 2010-09-29T06:03:54+09:00 Subject: Re: puts and return On Tue, Sep 28, 2010 at 4:29 PM, Jim Haungs wrote: > Interesting. Thanks. > > One sees control code like this in rails all the time: > > redirect_to and return if > > Never having looked at the return value from redirect_to (but guessing > it's always non-nil), I guess I assumed 'and' was the non-short-circuit > operator. > > Otherwise, why this is idiom so prevalent?  Because it looks more > English-like? Because it was the recommended way to get around 'double render' errors in the early days of Rails, and yes and is more English-like. The problem is that the and and or operators have a surprisingly low precedence, so for example a = 1 b = 2 x = a >0 and b < 1 sets x to true, then evaluates b < 1 returning false and throws the result away. I've seen too many problems caused by this that I eschew and in favor of && almost? everywhere in my ruby code. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale