Skip to content

Instantly share code, notes, and snippets.

@chiragmongia
Created July 31, 2013 07:36
Show Gist options
  • Select an option

  • Save chiragmongia/6120069 to your computer and use it in GitHub Desktop.

Select an option

Save chiragmongia/6120069 to your computer and use it in GitHub Desktop.
#Question- Reverse Sentence
#Use string methods to reverse the words arrangement in a sentence.
#Eg: "An apple a day keeps the doctor away" -> "away doctor the keeps day a apple An"
def reverse_string (input_string)
input_string.split.reverse!.join(" ")
end
#Main
p "Enter the string"
input_string = gets.chomp
puts "---String Reversed---"
puts reverse_string (input_string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment