Basic Ruby: what is the difference between these 2 codes? i get false for one and true for another : I got these 2 codes from 2 websites defining the longest word in a string but one code gives me true and one gives me false. Can someone tell me why?

    def longest_word(sentence)
      words = sentence.split(" ")
    
      longest_word = nil
    
      word_idx = 0
      while word_idx < words.length
        current_word = words[word_idx]
    
        if longest_word == nil
          longest_word = current_word
        elsif longest_word.length < current_word.length
          longest_word = current_word
        end
    
        word_idx += 1
      end
    
      return longest_word
    end
    
    AND
    
    
    def LongestWord(sen)
    
      arr = sen.split.map do |w| 
        /[a-zA-Z0-9\s]+/.match(w) 
      end

      longest = arr.max_by do |w| 
          w.to_s.length 
      end
      
      return longest
             
    end
       