On Sun, Oct 16, 2011 at 7:15 PM, teresa nuagen
<s-unguyen2 / huskers.unl.edu> wrote:
> "Jes Gabriel y Gal" <jgabrielygalan / gmail.com> wrote in post
> #1026842:
>> On Sun, Oct 16, 2011 at 2:04 AM, Teresa Nguyen
>> <s-unguyen2 / huskers.unl.edu> 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!

I guess, looking at the problem description, that you are learning
Ruby and/or programming, and that this is some kind of exercise. So it
would be wrong for me to give you a solution, since the purpose of an
excercise is to learn by trying. Let us see what you have tried. Ruby
has an interactive shell (irb) where you can try how all the functions
work, so you can learn by trying and then apply that knowledge to the
problem at hand. I recommend you take a look at these two pages:

http://www.ruby-doc.org/core/String.html
http://www.ruby-doc.org/core/Array.html

and get familiar with the methods in the Array and String classes.
This will help you solve many problems. In this specific case, I think
you can solve your problem using String#split, Array#reverse and
String#reverse. You will also need to know how to iterate an array:

array = [1,2,3,4,5]
array.each do |element|
  puts element
end

will print
1
2
3
4
5

With this knowledge and reading carefully the documentation of split
and reverse, I think you can manage to solve the problem. If you have
any specific question about methods or you get blocked by something
you don't understand, let us know.

Good luck !

Jesus.