I'm new to Ruby. I'm trying to learn the dos and don'ts by making little programs. This program is a little redundant, but I wanna better myself with the syntax of the language.
Anyways, so I'm trying to create a little program that will ask the user for an amount of people. This amount of people will then reference the size of the array, then the program will ask the user to enter the names for each element in the array (which ALL be "nil" values since the new array's elements will be empty). Finally, I would want to print back the array to the console to see the completed elements.
However, I'm getting an error saying "Line 10: TypeError occured. No implicit conversion from nil to integer". My code is not 100% done. I'm still trying to add more stuff to it, but I want to troubleshoot this error first before I go about doing that. Anyone out there willing to help me out ?
Here's the code
def Array_Maker
puts "How many people would you like to enter? : "
num = gets.chomp.to_i
nameArray = Array.new(num)
puts "\nEnter the names of the people you wish to add: "
nameArray.each do |x|
nameArray[x] = gets.chomp.to_s
end
nameArray.each do |x|
puts x
end
end
Array_Maker()
I'm probably doing this all wrong, but I'm trying...
gets.chomp.to_iasgets.to_iand sincegets.chompis a string,.to_singets.chomp.to_shas no effect.