[ruby-list:50571] Ubuntu v17 Ruby2.3.1p112
From:
sendf lusd <gtnfroesdas@...>
Date:
2017-09-02 03:56:25 UTC
List:
ruby-list #50571
Ruby2.3にて学生名、その学生の点数(一つだけとします)を管理するクラスを作成したのですが
# Student list
class student
def initialize()
@@StudentName[1] = nil
@@StudentPoint[1] = 0
end
def WriteStudentDate(Name,Point)
@@StudentName.push(Name)
@@StudentPoint.push(Point)
end
end
if __FILE__ = $0
student_obj = student.new
loop do
StdnName = gets
StdnPoint = gets
TempName = StdnName.chomp!
TempPoint = StdnPoint.chomp!.to_i
student_obj.WriteStudentDate(TempName,TempPoint)
end
[期待している動作]
hoge$ruby Student.rb
--------------------------------
Name: 山田
Point : 100
Name: 田中
Point : 100
//この繰り返し
--------------------------------
def WriteStudentDate(Name,Point)
この部分なのですが、Name,Pointが定数ではないとのエラーが発生し学生の人数分だけ配列を動的にサイズを変更していくことができません
Rubyで学生の人数分だけ配列のサイズを変更していくにはどうすればいいのでしょうか?