Understanding ruby array sort
- by user257797
I am having a problem understanding how array.sort{|x,y| block} works exactly,hence how to use it?
ruby-doc example:
a = [ "d", "a", "e", "c", "b" ]
a.sort #=> ["a", "b", "c", "d", "e"]
a.sort {|x,y| y <=> x } #=> ["e", "d", "c", "b", "a"]
thanks