Ruby - Write program to get the longest word in a sentence

Requirements

Write program to get the longest word in a sentence

Hint

The each iterator allows you to go through all the elements of an array and use the data you retrieve to work out.

Demo

my_array = %w{this is a test of the longest word check} 
longest_word = '' 
my_array.each do |word| # from  w  ww  .  j  a v  a 2 s.  com
  longest_word = word if longest_word.length < word.length 
end 
puts longest_word

Result

Related Exercise