On Behalf Of Cool Wong: # if the array include the "nil", it cannot sort, why?? # ["a", "a", "a", "b", "b", "c", "c", "c","d", "d", "e", nil].uniq.sort mainly because 1 sort expects same class for comparison irb(main):011:0> [1,"a"].sort ArgumentError: comparison of Fixnum with String failed from (irb):11:in `sort' 2 nil does not have comparison method <=> irb(main):012:0> [nil,nil].sort NoMethodError: undefined method `<=>' for nil:NilClass from (irb):12:in `sort' solution: a) convert elements to some common class (string is common) b) filter those you don't want sorted (using compact/reject/..) or select those you want (using select/map/..) A little digression for everyone though... irb(main):013:0> [nil].sort => [nil] is that intended? kind regards -botp