From: "Crispian A." Date: 2013-07-25T22:34:33+09:00 Subject: Re: Ruby newbie question on Methods (NoMethoderror) Crispian A. wrote in post #1116647: > I have recently started learning ruby and so I am writing a small little > program that takes user input and display on screen. > > I am using Aptana Studio 3 as well. > > I am getting a small error that says the following: > > C:/Users/Gemini/Documents/Aptana Studio 3 > Workspace/rubyProject/rubyTest.rb:51:in `
': undefined method > `games' for main:Object (NoMethodError) > > My Code here where the problem exists: > > puts "Would you like to play a game?(Y/N)" > userAnswer = gets.chomp > puts "You said #{userAnswer}" > > if userAnswer == "Y" > puts "Please choose from the list below:" > > games = ["Pacman", "Mario Brothers", "Bomberman"] > puts "#{games}" > > puts "Select between 0 and 2 to select your game of choice" > selectGame = games(gets.chomp) > puts " You chose #{selectGame(gets.chomp)}" > > elsif userAnswer == "N" > puts "Do you not like games?(Y/N)" > userAnswer = gets.chomp > > else puts "You did not choose an option!" > > end Thanks for the help it worked straight away. Didn't see where I went wrong. I was using parentheses instead of the brace to access the array. So in turn when entering an array index number on the selectGame = games[gets.chomp.to_i] it returns the string value of the indexed number entered by the user And where I have # puts "You chose #{selectGame.gets.chomp}" it already has stored the user input so I don't need the gets.chomp method there. Thanks for the help all. -- Posted via http://www.ruby-forum.com/.