title: How Yield statement in ruby works?
body: <p>Can someone please show how to correctly format this yield statement, and why my methodology for this yield statement is incorrect? When run, the compiler results in an "undefined method 'length' error. "Test" is the main class. </p>
  
  <pre><code>  def bubble_sort_by(array)
      len = array.length - 1
      while len &gt; 0
        for i in(1..len)
          @left = array[i]
          @right = array[i - 1]
          yield
          if @left - @right &gt; 0
             array[i - 1], array[i] = array[i], array[i - 1]
          end
        end
        len -= 1
      end
     p array
  end
  
    Test.bubble_sort_by(%w[hi hello hey]) do |left, right|
      left.length - right.length
    end
  </code></pre>