Possible Duplicate:
Is there a clean way to avoid calling a method on nil in a nested params hash?
Is there an easy way to check if a value in a multi dimensional hash is set without catching the NoMethodException?
Ex.:
do_x if cat['level1']['level2']['level3'] != 'value'
The problem is, that 'level2' might not even exist, so the receiver is nil.
In PHP you can just put an '@' in front to suppress the error.
In Ruby I would have to wrap the check in a begin-rescue block.
Is there a quick solution like in PHP?