On 10/18/05, Peter Fitzgibbons <peter.fitzgibbons / gmail.com> wrote:
> Hello all,
>
> I have this :
>
> def mymethod
>   a = someobjectreference('a')
>   if a.nil?
>     return nil
>   end
>   b = a.someattribute_might_be_nil
>   if b.nil?
>     return nil
>   end
>   c = b.someattribute_might_be_nil
>   if c.nil?
>     return nil
>   end
>   c.dosomething
> end

One possibility:

  def mymethod(a = nil)
    a.attr1.attr2.do_something
  rescue NoMethodError
    return nil
  end

You may want to disambiguate the NoMethod error to make sure it's not
raised in #do_something:

  def mymethod(a = nil)
    c = a.attr1.attr2 rescue return nil
    c.do_something
  end

-austin
--
Austin Ziegler * halostatue / gmail.com
               * Alternate: austin / halostatue.ca