這是我的報告控制器中的代碼,它看起來很糟糕,任何人都可以給我一些關於如何整理它的建議嗎?如何重構這個Ruby(控制器)代碼?
# app\controller\reports_controller.rb
@report_lines = []
@sum_wp, @sum_projcted_wp, @sum_il, @sum_projcted_il, @sum_li,@sum_gross_profit ,@sum_opportunities = [0,0,0,0,0,0,0]
date = @start_date
num_of_months.times do
wp,projected_wp, invoice_line,projected_il,line_item, opp = Report.data_of_invoicing_and_delivery_report(@part_or_service,date)
@sum_wp += wp
@sum_projcted_wp +=projected_wp
@sum_il=invoice_line
@sum_projcted_il +=projected_il
@sum_li += line_item
gross_profit = invoice_line - line_item
@sum_gross_profit += gross_profit
@sum_opportunities += opp
@report_lines << [date.strftime("%m/%Y"),wp,projected_wp ,invoice_line,projected_il,line_item,gross_profit,opp]
date = date.next_month
end
我期待用一些方法像
@sum_a,@sum_b,@sum_c += [1,2,3]
感謝您的提示,但是我正在尋找使用像 @ sum_a,@ sum_b,@ sum_c + = [1,2,3] 這個任何想法的一些方法? – 2009-06-03 08:45:19