Ruby on Rails
Tuesday, July 2, 2013
@formatted_question.each_pair do |key, value|
@formatted_question[key] = @question[:correct_anno] if value.length < 2
end
--
Dheeraj Kumar
On Wednesday 3 July 2013 at 8:19 AM, Dave Castellano wrote:
Hello,I'm learning rails and starting to try to refactor code that repeatsitself..I have several lines of code like the following and wonder if there is amore efficient way to do this. Any suggestions would be greatlyappreciated as one example would help me figure out how to refactor alotof my code.if @formatted_question[:anno_a].length < 2@formatted_question[:anno_a] = @question[:correct_anno]endif @formatted_question[:anno_b].length < 2@formatted_question[:anno_b] = @question[:correct_anno]endif @formatted_question[:anno_c].length < 2@formatted_question[:anno_c] = @question[:correct_anno]endif @formatted_question[:anno_d].length < 2@formatted_question[:anno_d] = @question[:correct_anno]endif @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@googlegroups.com.To post to this group, send email to rubyonrails-talk@googlegroups.com.To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c7c1664c60f0c30b690385a7d9ee014d%40ruby-forum.com.For more options, visit https://groups.google.com/groups/opt_out.
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@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/06D4719696FD4CE78EAB13A873952EA5%40gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment