Help refactoring

Dave Castellano
Wed, 03 Jul 2013 02:49:21 -0000

Hello,

I''m learning rails and starting to try to refactor code that repeats
itself..

I have several lines of code like the following and wonder if there is a
more efficient way to do this.  Any suggestions would be greatly
appreciated as one example would help me figure out how to refactor alot
of my code.

   if @formatted_question[:anno_a].length  < 2
      @formatted_question[:anno_a] = @question[:correct_anno]
    end
    if @formatted_question[:anno_b].length < 2
      @formatted_question[:anno_b] = @question[:correct_anno]
    end
    if @formatted_question[:anno_c].length < 2
      @formatted_question[:anno_c] = @question[:correct_anno]
    end
    if @formatted_question[:anno_d].length < 2
      @formatted_question[:anno_d] = @question[:correct_anno]
    end
    if @formatted_question[:anno_e].length < 2
      @formatted_question[:anno_e] = @question[:correct_anno]
    end

--
Posted via http://www.ruby-forum.com/.

--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit