Hi,
Also I was reading something about {} last night and it looks like I could write this as total = 0 7.times do |i| { total += row.send("day" + (i+1).to_s) } They both are pretty legible to me, but is there a major convention I should follow?
How about: total = 0 1.upto(7) { |i| total += row.send("day#{i}") }
How about a one-liner?
total = (1…7).inject {|sum, i| sum + row.send “day#{i}”}
Docs on inject:
Cheers! Patrick