From: Stefano Crocco Date: 2010-01-29T06:01:28+09:00 Subject: Re: What am I doing wrong? On Thursday 28 January 2010, Ast Jay wrote: > |I didn't see a beginners forum - hope it's ok to post this here. > | > |I feel so daft as this must be the simplest question you've probably > |been asked! > | > |Anyway I'm new to Ruby and want to create a very simple script that > |generates 100 random words and puts them into an array. I want to put > |them into an array so I can use array.uniq! so there are no duplicates. > | > |Here's my code so far (although I have tried lots of variations > |already). > | > |---------------- > |def create_word > | first_letter = ["b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", > |"p", "q", "r", "s", "t", "v", "w", "x", "y", "z"].shuffle[0..6].join > |end > | > |def create_list(word) > | words = [] > | words << word > |end > | > |100.times do > | list << create_list(create_word) > | puts list > |end > | > |-------- > | > |Like I said I am a beginner... well that's my excuse lol. > | > |Hope someone can help! First of all it would be better, when asking for help, to tell exactly what the problem is (for example, including the error message you obtain or explaining why the result your code produces is not what you expected). This way, you make things easier for people wanting to help you. As for your code. The error is in the line list << create_list(create_word) The problem is that something called list has never been defined before, so ruby doesn't know what to do with it. What you wanted is list = create_list(create_word) This creates a local variable called list and stores inside it the value that the create_list method returns. I hope this helps Stefano