Your code, as indicated, works great.
Extrapolating from your error, I assume that you actual code looks more like this:
class MyClass
def [](arg)
self.bim
self.bam
self.boom
rescue Exception
"--"
end
end
And what later do you try:
obj[ 'whatever' ]
undefined method []' for nil:NilClass' (NoMethodError). . B/c MyClass#[], b/c obj MyClass, it nil. , .