since the characters do not respond to the <=> method used by sorting, does anyone have a method to sort the character array? interested in seeing some other ideas.
Well, it symbols.sort_by {|sym| sym.to_s}works.
symbols.sort_by {|sym| sym.to_s}
Also in 1.9 characters answer to <=>, so you can just do symbols.sort.
<=>
symbols.sort
If you want to work with older rubies, as if they were 1.9, you can simply define <=> on Symbol
class Symbol include Comparable def <=>(other) self.to_s <=> other.to_s end end
You can use stone backports:
backports
require 'rubygems' require 'backports/1.9.1/symbol/comparison' [:a, :d, :c, :b].sort # => [:a, :b, :c, :d]