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: cocktail_sort.rb
    path of file: ./repos/Ruby/sorting
    
    the code of the file until where you have to start completion: def cocktail_sort(array)
  start = 0
  finish = array.length - 1
  way = 1
  loop do
    swapped = false
    start.step(finish - way, way) do |i|
      if (array[i] <=> array[i + way]) == way
        array[i], array[i + way] = array[i + way], array[i]
        swapped = i
      end

    
def cocktail_sort(array)
  start = 0
  finish = array.length - 1
  way = 1
  loop do
    swapped = false
    start.step(finish - way, way) do |i|
      if (array[i] <=> array[i + way]) == way
        array[i], array[i + way] = array[i + way], array[i]
        swapped = i
      end
    end
    break unless swapped

    finish = start
    start = swapped
    way = -way
  end