Ruby on Rails Friday, November 6, 2015

On 5 November 2015 at 23:17, wbsurfver@yahoo.com <wbsurfver@gmail.com> wrote:
>
> instead of this:
>
> def rqstate
> self.quote_request.status rescue "unsubmitted"
> end
>
> I'm going for this, though maybe there is a good one liner I overlooked ?
>
> def rqstate
> ret_res = "unsubmitted"
> ret_res = quote_request.status || ret_res if quote_request
> ret_res
> end

How about
def rqstate
(quote_request && quote_request.status) ? quote_request.status :
"unsubmitted"
end

Not only a one liner but I think easier to understand. Assuming I
have got it right :)

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLtLLog2%2B3B0EV0gy4jwQLCt5FgUzBKZBRLRmmh95JEJQg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment