Skip to content

Latest commit

 

History

History
24 lines (18 loc) · 538 Bytes

reverse_of_string_in_ruby.md

File metadata and controls

24 lines (18 loc) · 538 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"