I have the following code:
url = file.s3_url.blank? ? file.url : file.s3_url
Is there a shorter way to write this?
Thanks!
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.
Well, you could write a method on whatever
fileis an instance of (sayS3File):Then it gets real simple:
As @tokland said, you could monkey patch
Objectto use anor_ifmethod, which would be implemented like this:This way, you’d be able to do this:
Or this: