On Mon, Feb 6, 2012 at 13:16, regedarek <dariusz.fins...@gmail.com> wrote:

> How to refactor its right way?

Without delving too deep into the actual logic....

You've got a bunch of "unless this else that".  Generally speaking, if
you're using an "else", using "unless" makes it much more difficult
for a reader to follow, because of the multiple negations.  With an
"else", stick to "if".

Other than that, I'd suggest organizing it along the lines of:

  if some error condition
    complain about this one
  elsif another error condition
    complain about that one
  elsif some other error condition
    complain about the other one
  # lather, rinse, repeat
  else  # all is happy!
    do what the user was trying to do
  end

Now, within the "do what the user was trying to do", you may wind up
finally being able to calculate or retrieve some things you need to
analyze further error conditions.  There are several approaches.  You
can just nest these again, within reason, or make the happy path a
method call, wherein you repeat that pattern.

-Dave

-- 
Dave Aronson:  Available Cleared Ruby on Rails Freelancer
(NoVa/DC/Remote) -- see www.DaveAronson.com, and blogs at
www.Codosaur.us, www.Dare2XL.com, www.RecruitingRants.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.

Reply via email to