I\'m trying to create method named longest_word that takes a sentence as an argument and The function will return the longest word of the sentence.
longest_word
My c
The shortest way is to use Enumerable's max_by:
max_by
def longest(string) string.split(" ").max_by(&:length) end