title: Ruby longest word in array
body: <p>I built this method to find the longest word in an array, but I'm wondering if there's a better way to have done it. I'm pretty new to Ruby, and just did this as an exercise for learning the <code>inject</code> method.</p>
  
  <p>It returns either the longest word in an array, or an array of the equal longest words.</p>
  
  <pre><code>class Array
    def longest_word
      # Convert array elements to strings in the event that they're not.
      test_array = self.collect { |e| e.to_s }
      test_array.inject() do |word, comparison|
        if word.kind_of?(Array) then
          if word[0].length == comparison.length then
            word &lt;&lt; comparison
          else
            word[0].length &gt; comparison.length ? word : comparison
          end
        else
          # If words are equal, they are pushed into an array
          if word.length == comparison.length then
            the_words = Array.new
            the_words &lt;&lt; word
            the_words &lt;&lt; comparison
          else
            word.length &gt; comparison.length ? word : comparison
          end
        end
      end
    end
  end
  </code></pre>