From: "Brian F. Feldman" Date: 2001-01-08T04:17:34+09:00 Subject: [ruby-talk:8780] Re: No :<, :>, etc. methods for Array matz@zetabits.com (Yukihiro Matsumoto) wrote: > Hi, > > In message "[ruby-talk:8774] No :<, :>, etc. methods for Array" > on 01/01/07, "Brian F. Feldman" writes: > > |So, why not include Comparable in Array by default? It shouldn't have any > |bad side-effects, and it makes sense that if Array implements :<=>, it > |should then include Comparable. > > Because arrays are not always comparable. `sort', `min', and `max' in > Enumerable are the best compromise I could made. So it's done to "discourage" people from doing it? E.g. currently the best way to compare version numbers would be: irb(main):003:0> ([1, 6, 2] <=> [1, 4, 3]) == 1 true I also had a question if Array specifically could have a Array#sum method; the behavior would be very simple and straightforward: 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? -- Brian Fundakowski Feldman \ FreeBSD: The Power to Serve! / green@FreeBSD.org `------------------------------'