From: "Bartosz DziewoƄski" Date: 2012-09-13T19:46:12+09:00 Subject: Re: Breaking Down the Block 2012/9/13 7stud -- : > Or even better: > > class Array > def sum1 > initial_val_for_total = 0 > inject(initial_val_for_total) {|total, array_element| total += > array_element} > end > end Sorry, but that's bad practice in best case. #inject doesn't depend on the total being assigned to by the block; it depends on the value returned by the block. Your code works, but somebody may be tempted to do something like adding "p array_element" at the end and suddenly it breaks for no obvious reason, if somebody believed the assignment was essential. -- Matma Rex