On Fri, May 20, 2011 at 4:23 PM, Rob Biedenharn
<r...@agileconsultingllc.com>wrote:

> On May 20, 2011, at 5:05 PM, Curtis j Schofield wrote:
>
>  if notice = response_status_and_flash.delete(:notice)
>>    flash[:notice] = notice
>>  end
>>
>>
> This is a common C idiom.
>
> The best solution is to always write your == with the constant on the LEFT
> instead
> of the right.
>
> :D
> --
> make haste slowly \
> festina lente  \
> -
> mobile  +1_415_632_6001
> curtis.schofi...@gmail.com <cur...@robotarmyma.de>
> http://robotarmyma.de
>
>
> assuming that the intent is to call
> response_status_and_flash.delete(:notice) just once, test the result, and
> then use a truthy result in the flash[:notice], this is almost exactly what
> I typically type.
>
> However, I'd really put ( ) around the expression.
>
> if (notice = response_status_and_flash.delete(:notice))
>   flash[:notice] = notice
> end
>

This is definitely understandable without surprise, while I for sure did a
double take before understanding Kai's initial example.


>
> This is a trick from JSLint which will complain about assignments in the
> conditional expression of an if, but an extra pair of parentheses will
> signal your intent and silence the warning.
>
> -Rob
>
>
> Rob Biedenharn
> r...@agileconsultingllc.com http://AgileConsultingLLC.com/
> r...@gaslightsoftware.com <r...@gaslightsoftware.com>
> http://GaslightSoftware.com/
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to