From: John W Higgins Date: 2010-12-28T03:10:53+09:00 Subject: Re: inject issue --0016364266036e0b9404986841b2 Content-Type: text/plain; charset=ISO-8859-1 Good Morning, On Mon, Dec 27, 2010 at 9:25 AM, jzakiya wrote: > I was wondering why these are equivalent: > > a=(1..100).inject :+ > b=(1..100).inject 0, :+ > > Those are equivalent by luck only. With inject if you fail to provide the initial "value" (as you do in the first line) then the first element of the collection is used (in the first line it would be 1). So, for example if you used :* or :- instead of :+ for your two rows you would see a different result for the two rows - using :* would return a very large number for the first row and zero for the second row (the second row would just keep multiplying numbers by 0 which always equals 0). For :- you would have something like -5049 and the second row would be -5050 (or something close to that). In the example you provided your second row uses 0 as the initial value which means after processing the first element of the collection you are in the same position as not having provided the value, as the first row does, because 1 = 0 + 1. John --0016364266036e0b9404986841b2--