Gurmukh Singh Gurmukh Singh - 1 year ago 76
Ruby Question

unexpected ',' syntax error ruby

I'm learning ruby and have looked the internet to see whats wrong with this. I have tried adding spacing and removing it between the variables I'm passing but i keep getting this error:

25: syntax error, unexpected ',', expecting ')'
student1.grades =(60,70,80)

Here is the code:

class Student
attr_accessor :name, :age

def initialize(name,age)
@name = name
@age = age

def grades(math,english,science)
@math = math
@english = english
@science = science
average_grade = (math.to_i + english.to_i + science.to_i) / 3
return average_grade

def to_s
puts "Name = #{name}"
puts "Age = #{age}"
puts self.grades

student1 ="Tom","23")
student1.grades = (60,70,80)
puts student1

Answer Source

grades receives three parameters. You don't do that with assignment. So change

student1.grades = (60,70,80)


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download