I am having a problem understanding how array.sort{ |x,y| block } works exactly, hence how to use it?
An example from Ruby documentation:
<=> is a method is ruby that returns ( self.<=>( argument ) )
x and y are items of array. If no block is provided, the sort function uses x<=>y, otherwise the result of the block says if x should be before y.
array.sort{|x, y| some_very_complicated_method(x, y) }
Here if some_very_complicated_method(x, y) returns smth that is < 0, x is considered < than y and so on...