title: Understanding Ruby Class: "undefined method `<' for true:TrueClass"
body: <p>I'm following a class on Coursera and I'm trying to implement the quicksort algorithm in Ruby. I'm very new to the language and the concepts of OOP. </p>
  
  <p>I've created two functions: one which is the quickSort function which calls the partition routine (that splits the array into two subarrays according to the pivot which is the first element of the array). </p>
  
  <p>Eventually I'll put these two methods under a class Array, but for now I figured this would be OK. </p>
  
  <p>I tried running this on an array (a = [5, 4, 3, 2, 1]), but I run into the following error: </p>
  
  <pre><code>A2.rb:16:in `partition': undefined method `&lt;' for true:TrueClass (NoMethodError)
      from A2.rb:15:in `each'
      from A2.rb:15:in `partition'
      from A2.rb:33:in `quickSort'
  </code></pre>
  
  <p>Here's my code: </p>
  
  <pre><code>    def partition(array, left_idx, right_idx)
        num_comp = array.length - 1
        p = array[left_idx]
        i = left_idx + 1
        j = left_idx + 1
        puts "#{left_idx}, #{right_idx}, #{array[j]} #{j}"
        puts "pivot = #{p}"
        for j in (left_idx + 1..right_idx)
          if (left_idx &lt; j &lt; right_idx and left_idx &lt; i &lt; right_idx)
            if (array[j] &gt; p)
              j = j + 1
            else 
              array[i], array[j] = array[j], array[i]
              i = i + 1
              j = j + 1
            end
          end
        end
        #swap pivot and rightmost value in subarray that contains &lt; p
        array[1], array[i] = array[i], array[1]
        pivot_idx = i
        return array, num_comp, pivot_idx
      end
  
      def quickSort(array, start_idx, end_idx)
        array_n, num_comp, pivot_idx = partition(array, start_idx, end_idx)
        left_array = array_n[start_idx..pivot_idx - 1]
        right_array = array_n[pivot_idx + 1..end_idx]
        if (left_array.length &gt; 1) 
          array_n = quickSort(array_n, start_idx, pivot_idx - 1)
        end
        if (right_array.length &gt; 1)
          array_n = quickSort(array_n, pivot_idx + 1, end_idx)
        end
        return array
      end
  
      #a = Array.new()
      a = [5, 4, 3, 2, 1]
      quickSort(a, 0, 4)
      print "Array"
      puts a
  </code></pre>
  
  <p>Thanks</p>