Wednesday, 2 October 2013

ruby refactor redundant code block

ruby refactor redundant code block

I have some pretty straight-forward ruby logic below. I was wondering if
there was any way to make it more DRY, or perhaps if there was a more ruby
way to do this.
if @status == :status1
text.each_slice(3) do |x|
x.flatten!
row = Array.new
row << x[0...num].join(' ')
num.upto(-1) { |i| row << x[i] }
table << row
end
elsif @status == :status2
text.each do |x|
row = Array.new
row << x[0...num].join(' ')
num.upto(-1) { |i| row << x[i] }
table << row
end
end

No comments:

Post a Comment