You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: heapsort.rb
    path of file: ./repos/Algorithms/Sorting/Heapsort/Ruby
    
    the code of the file until where you have to start completion: # Builds a max heap in an array with the specified root
def heapify(array, size, root)
    left = 2*root + 1  # left child of the root
    right = 2*root + 2 # right child of the root 

    largest = root # set root to be the largest element

    i
    
def heap_sort(array)
    size = array.length
    i = (size/2) - 1
    # build a max heap from the array
    (size/2).times do
        heapify(array, size, i)
        i = i - 1
    end

    # extract elements from the heap one by one
    i = size-1
    size.times do
        array[0], array[i] = array[i], array[0] 
        # rebuild heap excluding elements that are placed correctly
        heapify(array, i, 0)
        i = i - 1
    end
end