From: "Jesús Gabriel y Galán" Date: 2010-08-19T15:56:04+09:00 Subject: Re: Check existence of object and it's property at the same time 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"). irb(main):004:0> member = nil => nil irb(main):005:0> if member or member.is_active? irb(main):006:1> puts "one or both were true" irb(main):007:1> end NoMethodError: undefined method `is_active?' for nil:NilClass from (irb):5 from :0 irb(main):008:0> member = "test" => "test" irb(main):009:0> if member or member.is_active? irb(main):010:1> puts "one or both were true" irb(main):011:1> end one or both were true Here you have the opposite situation: when the first truthy expression is found, the evaluation is shortcircuited to that value, as you can see that the is_active? method is not called in the last example. Jesus.