我想加载一个文件,将其内容拆分为数组,并将类应用于内容。
class Student
def initialize( name, grade )
@name = name
@grade = grade
@grade = @grade.to_i
@newgrade = @grade*1.45
end
def show()
return "#{@name} ,#{@grade} , #{@newgrade}"
end
end
# Opening the file into an array
arr = File.open("exam_results.txt", "r+")
allStudents = Array.new
for a in arr
b = a.split(",")
name = b[0]
score = b[1]
allStudents << Student.new(@name, @grade)
end
for i in Student
puts show()
end
我越来越
Student:Class (NoMethodError) 的未定义方法“每个”
在第 28 行,即该puts show()
行。关于我如何进一步了解这一点的任何线索?