I’m cycling through several different attributes looking for something not set to ""
To do this I wrote :
def email
begin
if email1 != ""
email1
elsif email2 != ""
email2
elsif email3 != ""
email3
else
Fail
end
rescue
"Undefined"
end
end
Basically, if it fails the logic on the first statement, I’d like it to be rescued.
Perhaps rescue isn’t the right decision. What would you recommend?
First off,
defis an implicitbegin, so you can save yourself that. However, from your limited description, I think this should work for you:It either returns the first set email address or “undefined”. My version reads a bit more like how you would describe the problem (take the first set email address or return “undefined”), mu’s version is a bit more compact and probably what I’d use.