unbewusst.sein
12/6/2007 7:37:00 PM
I've done a "self <=> anotherString" comparaison which works by itself :
class String
def <=>( aString )
[blahblahblah]
end
end
however if i want to sort an Array of Strings, the Array is sorted as
usual within Ruby (put accentuated characters at the end) :
a = [ "Être", "Fenêtre", "Etre" ]
b = a.sort { | i, j | i <=> j }
puts "b = [ " + b.join(", ") + " ]\n"
# => b = [ Etre, Être, Fenêtre ]
c = a.sort #<=>( aString ) NOT CALLED...
puts "c = [ " + c.join(", ") + " ]\n"
# => c = [ Etre, Fenêtre, Être ]
Why, in the case of "c = a.sort", #<=>( aString ) isn't called ?
the comparaison within an Array could compare different kind of objects
like :
a = [ 0, "a", 9, Time.new ] ???
--
Une Bévue