From: "Brian F. Feldman" Date: 2001-01-08T04:45:31+09:00 Subject: [ruby-talk:8782] Re: No :<, :>, etc. methods for Array gotoken@math.sci.hokudai.ac.jp (GOTO Kentaro) wrote: > In message "[ruby-talk:8780] Re: No :<, :>, etc. methods for Array" > on 01/01/08, "Brian F. Feldman" writes: > >class Array > > def sum > > total = self[0] # defaults to nil > > self[1..-1].each {|x| total += x} > > total > > end > >end > > > >It simplifies lots of things (especially mathematics) in Ruby to have it, > >and I believe it's generally useful enough that it should probably be > >standard. What do you think? > > See: > http://www.rubycentral.com/faq/rubyfaq-11.html#ss11.4 > > `Enumerable#inject' is introduced there. That may be adopted if an > apter method name is proposed. Except that I don't really ever see the need for the inject functionality itself. A general sum method wouldn't prevent an inject method from being created, and I feel it's much more generally important (if it were in Enumerable, it feels natural next to min and max). I know you can define sum in terms of inject, but what is the point of having inject if people are just going to use it to create sum? -- Brian Fundakowski Feldman \ FreeBSD: The Power to Serve! / green@FreeBSD.org `------------------------------'