From: Sam Stephenson Date: 2004-07-12T08:15:13+09:00 Subject: Re: Ruby quickies and useful idioms On Mon, 12 Jul 2004 07:47:12 +0900, Gavin Sinclair wrote: > 'foldl' is, I believe, the same as Enumeration#inject. Try checking > out the docs for that, but: > > (1..100).inject(0) { |acc,x| acc + x } Wow, I didn't know about Enumerable#inject. Semantically, it's not quite the same as foldl: for instance, it doesn't make sense to foldl (or foldr) a Hash, since you're not guaranteed any order. Practically speaking, however, it's much nicer, since I can use it with Range. As an aside: It would be nice to have a subclass of Enumerable that guarantees item order; Array, Range, et al could mix it in. > For more of these, check out > > www.rubygarden.org/ruby?StandardClassExtentions > > Some of those, and others besides, are coded up in the 'extensions' > project on RubyForge, for which I'll gratefully receive suggestions. Cool, thanks! Sam