I am just trying to understand the Ruby sort function and the blocks, and I came up with the following code:
a = [1,2,3]
a.sort do |x,y|
x
end
Won't the returning x be taken as the factor to sort the two elements? I expect the following behaviour:
1,2get passed as block parameters,1is returned.2,3get passed as block parameters,2is returned.1,3get passed as block parameters,3is returned.
So considering the returned values, won't the sorted array still be [1,2,3]? Where am I getting it wrong?
sort_by.