From: Robert Klemme Date: 2010-08-19T21:42:56+09:00 Subject: Re: Check existence of object and it's property at the same time 2010/8/19 Jesús Gabriel y Galán : > On Wed, Aug 18, 2010 at 11:47 PM, Cory Patterson wrote: >> David, >> >> You are completely correct.  I guess that was a bad example.  So the >> order of the conditions is important: >>>> if @member and @member.is_active?; end >> => nil >>>> if @member.is_active? && @member; end >> NoMethodError: undefined method `is_active?' for nil:NilClass >> > > Yes, it's important. Ruby starts evaluating from left to right, and > will shortcircuit on the first value that would make the whole > expression false (or true if it's an "or"). For the record: short circuiting also happens in Enumerable#any? and #all?. And btw, the same short circuiting is done in Java and I guess most modern languages. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/