From: "Jesús Gabriel y Galán" Date: 2011-10-16T16:36:05+09:00 Subject: Re: writing a poem backwards or in reverse order On Sun, Oct 16, 2011 at 2:04 AM, Teresa Nguyen wrote: > i would like to write a poem using nano and through ruby I would like to > do the following: > > Program 1: > > Reads the poem into the program and writes it to the screen backwards > from last line to first. Use String#split to split the poem into lines. Then iterate from last line to first line, outputting each line. > Program 2: > > Reads the poem into the program and writes it to the screen backwards > from last line to first with the words of each line in reverse order. The same as above, but also use String#split to divide each line into words. When outputting each line, iterate over the words in the line from last word to first word. > Program 3: > > Reads the poem into the program and prints the poem to the screen > backwards from last line to first with the words of each line in reverse > order and the characters in each word in reverse order. The same as 2, but using String#reverse to output each word. > I'm new to ruby and I have been trying to play around with it. Can you > help me approach this problem. > I know that I have to apply using a string called "split" in order to > write backwards from last line to first line with the words in reverse > order. Can you help me? Take a look at the String documentation, in particular: http://www.ruby-doc.org/core-1.9.2/String.html#method-i-split Let us know how you progress. Jesus.