I want to loop through an array of one word strings and turn them into instances of a class. Something like this:
names_array = ["jack", "james","jim"]
names_array.each { |name| name = Person.new }
I've tried using eval like (names_array.each { |name| eval(name) = Person.new }
) but this doesn't seem to work. Is there anyway of doing this in Ruby?
EDIT Previous example was a little off on what I am really trying to do here is my exacted code.
students = ["Alex","Penelope" ,"Peter","Leighton","Jacob"]
students_hash = Hash.new {|hash, key| key = { :name => key, :scores => Array.new(5){|index| index = (1..100).to_a.sample} } }
students.map! {|student| students_hash[student]}
Where my problem is
students.each {|student_hash| eval(student_hash[:name].downcase) = Student.new(students_hash)}