From: claire pengelly Date: 2012-02-04T07:56:19+09:00 Subject: Difficulty writing a sorting method (Chris Pine's Learn to Program) Hi all, I'm very, very new to programming and have been working through Chris Pine's book. The assignment I'm working on is to write a sorting method without just using .sort or recursion. It should sort a list of words alphabetically. Here is what I have so far: #get list of words puts "Hello, type as many words as you want, with one word per line!" words = [] already_sorted = [] unsorted = [] while true word = gets.chomp.capitalize if word == '' break end end words.push word #defining the sorting method words[0] = w def alpha_sort words while w < 1 if w < words.all? already_sorted << w end end while w < words.length if w < unsorted.all? already_sorted << w end w += 1 end end puts(alpha_sort(words)) The problem seems to be in using a variable to represent the array from the earlier list as part of defining the alpha_sort method? I don't know why that would be a problem though. And I'm sure there's probably a bunch of other stuff wrong with it that I can't even see! Getting the word list works fine, but afterwards this is the error I get when running it: "newwordlist.rb:14:in 'main': undefined local variable or method 'w' for main:Object (name error)" Thanks for your suggestions! -- Posted via http://www.ruby-forum.com/.