From: spiralofhope Date: 2011-04-22T13:32:07+09:00 Subject: Re: Reversing a string without using array, classes and reverse function On Fri, 22 Apr 2011 12:54:16 +0900 Rubist Rohit wrote: > I am trying this: > > mystring = gets > mystring.scan(/..$/) {|x| puts x} > > It returns only the last character. Is it possible to add the above > line in loop? Here's something I stumbled through which seems to work. - Using a regex of /.$/ - Slowly chomping away at the original string. - Using another variable to build my result. mystring = 'Hello, World!' result = '' fail = 0 until fail == "100" or mystring == '' do fail += 1 mystring.match( %r{(.$)} ) break if $~ == nil result += $~[1] mystring = mystring.chomp( $~[1] ) end puts result -- http://spiralofhope.com