On Mon, 2004-10-11 at 22:14, Bill wrote: > One problem: I cannot find documentation for the Dir.inject method. I > assume from some of the Ruby docs this is like the Smalltalk inject > method, but I don't know why it's not documented in the Dir class? Yes, very much like. It is a mix-in, from the module Enumerable; thus anything that has an each & includes Enumerable (e.g. arrays, files, etc.) supports inject. Rather than documenting it for each of these most references just list the "mix-ins" of a class as a reminder that you are getting some extra goodies for free. > Anyway, what, exactly, is happening in the line (typo removed) > > > moved = dir.inject(0) do |count, logfile| > > and how do you know to put the | count, logfile | variables in that > order, and not | logfile, count | ? Inject works on the model of "injecting" an operator between each element of an Enumerable collection, prefaced with a starting value. Thus: [2,5,7,4].inject(0) { |running_total,x| running_total + x } means: 0 + 2 + 5 + 7 + 4 or (in case order of evaluation matters to you): (((0 + 2) + 5) + 7) + 4 just like (IIRC) in smalltalk. -- Markus