From: "Jesús Gabriel y Galán" Date: 2013-07-25T19:36:01+09:00 Subject: Re: Ruby newbie question on Methods (NoMethoderror) On Thu, Jul 25, 2013 at 12:22 PM, Crispian A. wrote: > 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) You are using brackets, and that is a method call. You need square brackets games[gets.chomp] but also, arrays are indexed by integers, so you would need to convert the user's input: games[gets.to_i] # to_i removes non number characters like \n already and will default to 0 if it can read a number from the string > 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 Hope this helps, Jesus.