From: teresa nuagen Date: 2011-10-17T08:54:33+09:00 Subject: Re: writing a poem backwards or in reverse order Josh Cheek wrote in post #1026937: > On Sun, Oct 16, 2011 at 5:14 PM, teresa nuagen > wrote: > >> >> -- >> > >> order and the characters in each word in reverse order. >> >> -- >> Posted via http://www.ruby-forum.com/. >> >> > > This is like your program 1, but just slightly different. You will need > to > write the reverse_words function yourself, try writing it separately > from > the rest of the program, and then when you are satisfied it is correct, > use > it as shown below. > > > > > def reverse_words(line) > end > > contents = File.read("poem") > puts contents > > my_file = File.new("poem") > line_array = my_file.readlines() > line_array.reverse! > line_array.each { |line| puts reverse_words(line) } > > my_file.close when using this method, I got an error message that says: poem_program2.rb:7:in `block in
': undefined method `reverse_words' for main:Object (NoMethodError) from poem_program2.rb:7:in `each' from poem_program2.rb:7:in `
' Is there another way to approach the method using string and how would I go about it to reverse and go from last line to first in reverse order? -- Posted via http://www.ruby-forum.com/.