I was wandering about the correct way to do the following.
a = b or c
where only one of b or c will be defined.
EDIT:
Thanks for the answers, just to clarify by not defined they are not defined at all (i.e not nil)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If only one or the other actually exists, you’ll need to use
defined?for local variables.With instance variables it is a little easier, assuming neither value should be falsy, since they are implicitly
nilbefore they are defined: