Skip to content

Instantly share code, notes, and snippets.

@kmandreza
Created January 3, 2013 10:01
Show Gist options
  • Select an option

  • Save kmandreza/4442356 to your computer and use it in GitHub Desktop.

Select an option

Save kmandreza/4442356 to your computer and use it in GitHub Desktop.
Write a method reverse_words which takes a sentence as a string and reverse each word in it.
def reverse_words(str)
array = str.split(' ')
array.each do |x|
x.reverse!
end
array.join(' ')
end
@kmandreza
Copy link
Author

if I removed the exclamation point, how could I still make the method work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment