我有多个ActiveRecord
子类Item
的实例数组,它们需要根据最早的事件循环打印。在这种情况下,我需要打印的打印出来的付款和维护日期如下:5天in 3天需要
B项支付7天
需要
项目的支付需要循环遍历Ruby中的多个阵列
项目A保养。中8天
需要B项维修
我现在有寻找maintenance
两个查询和payment
项目(非排他性查询)和类似以下输出它们:
<%- item_p = nil -%>
<%- item_m = nil -%>
<%- loop do -%>
<% item_p ||= @items_p.shift %>
<% item_m ||= @items_m.shift %>
<%- if item_p.nil? and item_m.nil? then break -%>
<%- elsif item_p and (item_m.nil? or item_p.paymt < item_m.maint) then -%>
<%= item_p.name %> payment required in ...
<%- elsif item_m and (item_p.nil? or item_m.maint < item_p.paymt) then -%>
<%= item_m.name %> maintenance required in ...
<%- end -%>
<%- end -%>
任何方式来清理上面(丑)代码的可读性?
+1这也是我的想法,很自然地我喜欢这个想法:-) – DigitalRoss 2011-06-07 20:51:48