Skip to content

Instantly share code, notes, and snippets.

@Stephenitis
Created February 14, 2013 08:26
Show Gist options
  • Save Stephenitis/4951331 to your computer and use it in GitHub Desktop.
Save Stephenitis/4951331 to your computer and use it in GitHub Desktop.
Exercise: Reverse words Write a method reverse_words which takes a sentence as a string and reverse each word in it.
def reverse_words(str)
a = str.split.collect { |word| word.reverse }
a.join(" ")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment