我有以下代碼:替換轉置方法?
table([
["UnitID", "First Name", "NPS Score", "Comments"],
*[invite_unitid_arr, invite_name_arr, nps_score_integers_final, comment_arr]
.transpose.reject{ |x| x[3].empty? }
], :position => :center, :column_widths => {0 => 50, 1 => 60, 2 => 60, 3 => 40, 4 => 150}) do
row(0).style :background_color => 'C0C0C0'
end
我打電話transpose
數組的數組上。我重構此代碼,我現在有模型對象的數組:
array = Model.all
我怎樣才能把上面的,說:「循環每一個模型(模型1,模型2等),並創建與屬性的行unit_id,first_name,nps_score,評論如下:Model1[:unit_id],Model1[:first_name],Model1[:nps_score],Model1[:comment]
「