On 15 February 2011 01:18, Kai Middleton <[email protected]> wrote: > I was looking at this bit of code within Rails: > > # File actionpack/lib/action_controller/metal/flash.rb, line 12 > def redirect_to(options = {}, response_status_and_flash = {}) #:doc: > if alert = response_status_and_flash.delete(:alert) > flash[:alert] = alert > end > > if notice = response_status_and_flash.delete(:notice) > flash[:notice] = notice > end > > if other_flashes = response_status_and_flash.delete(:flash) > flash.update(other_flashes) > end > > super(options, response_status_and_flash) > end > > And I thought: ouch, aren't those supposed to be double-equals? Well, > no, it's an assignment within an if statement. It saves a line of > code per usage, thus three lines of code in that method. > > But I thought: wow, that sure violates the principle of least > surprise.
In that situation I would code it as if ( other_flashes = response_status_and_flash.delete(:flash) ) which arguably makes the intention clearer with only a few extra characters an no run time penalty. Colin -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

