From: "Martin Dürst" Date: 2011-11-06T16:14:12+09:00 Subject: [ruby-core:40766] [ruby-trunk - Feature #5574] Make arrays comparable Issue #5574 has been updated by Martin D��rst. I support this proposal. In a basic programming lecture, I just recently told students how to compare (<, <=, and so on) numbers and strings, and then mentioned that it would work the same way for Arrays. But then when I wanted to show this, it didn't work. I was quite surprised, because I had sorted Arrays many times before. Then I vaguely remembered: Ah, yes, there's a <=> operator for Arrays, but if you want to use <, <=, ..., you have to include Comparable. It's the way it currently is, but it's totally unclear why, and it's difficult to remember. ---------------------------------------- Feature #5574: Make arrays comparable http://redmine.ruby-lang.org/issues/5574 Author: Arnau Sanchez Status: Open Priority: Normal Assignee: Category: Target version: Why are arrays not comparable? _Array_ already defines _<=>_, so it seems only natural to mix-in the _Comparable_ module.
> [1, 2] < [1, 1] 
NoMethodError: undefined method `<' for [1, 2]:Array

> Array.send(:include, Comparable)
> [1, 2] < [1, 1] 
=> false
This was already discussed in the mailing list a while ago and people agreed it would be useful: http://www.ruby-forum.com/topic/76535 -- http://redmine.ruby-lang.org