When you call a method that does not exist on an object a NoMethodError will be raised i.e.
Object.new.foo
will output:
NoMethodError: undefined method `foo’ for #
while
nil.foo
will output:
NoMethodError: undefined method `foo’ for nil:NilClass
I want to copy this behaviour when raising an exception of my own, i.e.
foo = Object.new
raise StandardError, "#{foo} triggered an error"
which will output:
StandardError: #
<Object:0xbf37748>triggered an error
which is exatly what I want.
Unfortunately
foo = nil
raise StandardError, "#{foo} triggered an error"
will output
StandardError: triggered an error
which is probably because nil.to_s is "". How do I get nil:NillClass as output?
Edit. You seem to want
nilto behave differently. So prepare a different method just for using in yourraisestatement.