From: teresa nuagen Date: 2011-10-17T02:15:30+09:00 Subject: Re: writing a poem backwards or in reverse order "Jesús Gabriel y Galán" wrote in post #1026842: > 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. Alright, thanks so much for your response! Can you show me an example of this, like let's say I have these lines: waiting for hours wet at first, in the cold dark just to be gulped down How would I go about it, using the three programs described above. I will try to follow your example with a longer poem of my own. Thanks again for your help! I appreciate it! -- Posted via http://www.ruby-forum.com/.