If I create a student
class and each time a new student object is created, how do I dynamically create a new variable name to distinguish between the different students? I don't know how many students there will be.
On the last line of the code below I have used student1
as the variable name for the new student object. If I want to create 100 student objects and have the variable name be student1
through student100
how would I dynamically create these variable names?
class Student
attr_accessor :name
def initialize(name)
@name = name
puts "Hello #{name}"
end
end
puts "What is your name?"
answer = gets.chomp
student1 = Student.new(answer)