From: Stefano Crocco Date: 2010-12-27T17:27:19+09:00 Subject: Re: inject issue On Monday 27 December 2010 17:15:27 jzakiya wrote: > When I do this: > > %w/ap mathn roots facets/.inject :require > > whatever is the first item in the list doesn't get loaded by 'require' > > When I do this: > > %w/ap mathn roots facets/.inject 0, :require or .inject(0, :require) > > then the first item is also loaded. (the '0' can be essentially > anything) > > Is this a bug, or is this the expected operation? > > This behavior is consistent across 1.8.7, 1.9.1/2 and jruby using RVM. This is the expected behaviour. According to the ri documentation for inject, the value passed as argument is the initial value used for the block-local variable which stores the result and, if you don't give any, the first element of the array will be used as initial value, so the block (or, in your case, the method you use instead of the block) is not called on it. By the way, this is a very strange way to use inject, since you aren't actually interested in accumulating the values returned by the block (of course, assuming this is your actual code). In your case, a simple each should work: %w/ap mathn roots facets/.each{|f| require f} I hope this helps Stefano