From: Jeremy Kemper Date: 2005-10-19T04:39:27+09:00 Subject: Re: The Ruby Way to build an object unless nil? -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Oct 18, 2005, at 12:14 PM, Austin Ziegler wrote: > One possibility: > def mymethod(a = nil) > a.attr1.attr2.do_something > rescue NoMethodError > return nil > end I like that when I'm only concerned with the final value (e.g. in an erb template) <%= foo.bar.baz rescue nil %> otherwise, if a = foo and b = a.bar then b.baz end Regards, jeremy -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (Darwin) iD8DBQFDVU9qAQHALep9HFYRAuVyAJ4tac4WhOCtB6zEkVY8nhr4btygUQCg2Gda az395n6c6LrPmWlwVSlzOJ8= =ec6D -----END PGP SIGNATURE-----