From: teresa nuagen Date: 2011-10-17T07:49:45+09:00 Subject: Re: writing a poem backwards or in reverse order teresa nuagen wrote in post #1026938: >> 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 > > Alright, thank you. Is there a same method but using string? > is > > def reverse_words(line) > end > > included in the beginning of the file? when using an 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/.