Skip to content

Latest commit

 

History

History
18 lines (14 loc) · 522 Bytes

reverse_of_string_in_ruby.md

File metadata and controls

18 lines (14 loc) · 522 Bytes

Reverse String The below code will explain regarding reversing the string with using a reverse() function. Function named reverse_string describes the code to reverse the string in ruby.

def reverse_string(str) split_str = str.split("")' reverse_str = [] str.size.times { reverse_str << split_str.pop } reversed.join end

Calling the above function is given below:

str = gets.chomp.to_s # Dynamic Input puts reverse_string(str)

Input : "rubyonrails" Output : "sliarnoybur"