From: markus heiler Date: 2011-11-07T08:25:22+09:00 Subject: [ruby-core:40802] [ruby-trunk - Feature #5574] Make arrays comparable Issue #5574 has been updated by markus heiler. Ok so it does not yet exist because it can contain elements that are not comparable. But in the example given with the 1, 2] < [1, 1] all elements are comparable. Ruby wants you to include Comparable. But even when you do that, and then try to compare an invalid Array element: [1, 2] < [1, "adc"] You get an argument error: ArgumentError: comparison of Array with Array failed So I think the better way would be to include Comparable module in Array? ---------------------------------------- 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