On Fri, Nov 6, 2015 at 10:03 AM Colin Law wrote:
> On 5 November 2015 at 23:17, wbsurf...@yahoo.com
> wrote:
> >
> > instead of this:
> >
> > def rqstate
> >self.quote_request.status rescue "unsubmitted"
> > end
> >
> > I'm going for this, though
On 5 November 2015 at 23:17, wbsurf...@yahoo.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"
>
On 6 November 2015 at 09:31, Marco Antonio Almeida
wrote:
> On Fri, Nov 6, 2015 at 10:03 AM Colin Law wrote:
>> ...
>> How about
>> def rqstate
>> (quote_request && quote_request.status) ? quote_request.status :
>> "unsubmitted"
>> end
>
>
> If
On Friday, November 6, 2015 at 9:32:21 AM UTC, Marco Antonio Almeida wrote:
>
> If you're using Rails, another approach is to use try (
> http://apidock.com/rails/Object/try).
>
> def rqstate
> quote_request.try(:status) || "unsubmitted"
> end
>
> #try is very nice in this case, but avoid
rqstate is as follows, if there is not a quote request or the status field
is null then we could assume
that the request was never submitted to the backend api. This was actually
the first time I tried this approach but I am not sure I will keep it this
way
def rqstate
I know you can define actions as a block inside of rescue but that wasn't
what I meant
--
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
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
--
You
I was reading some ruby one liners. The rescue style seems to make it easy
to write short pieces of code, but it feels like I am forcing an error and
then just ignoring it in some cases. I guess I am an older programmer and
was never encouraged to write this sort of code, but do most people
This is terrible style and is strictly forbidden in our codebase.
In the example below, probably the programmer thought that an exception
always meant that quote_responses was nil instead of an array, and that nil
should be treated as an empty array. That works fine... until another
source of
9 matches
Mail list logo