Well, trying to write what I think (not that I know anything about it) is more Ruby-ish code, here is a mixin for the Array:
class Array
def mergesort
return self if (length<=1)
half = (length-1)/2
firstHalfOfTheList = slice(0..half)
secondHalfOfTheList = slice((half+1)..(length-1))
sortedFirstHalfOfTheList = firstHalfOfTheList.mergesort
sortedSecondHalfOfTheList = secondHalfOfTheList.mergesort
merge sortedFirstHalfOfTheList, sortedSecondHalfOfTheList
end
def merge(first, second)
merged = Array.new
firstlength = first.length
firstlength.times do
fp = first.shift
secondlength = second.length
secondlength.times do
sp = second.first
if sp < fp then
merged << second.shift
end
end
merged << fp
end
merged + second
end
end