我对ruby很新,并且已经在封装上编写了代码。但是面对错误是“语法错误,意外的keyword_end,期望第20行的输入结束”。任何人都可以帮助我知道什么是基础我收到了错误
Class Employee
def empdetails(name,empid,age,department)
@name=name
@empid=empid
@age=age
@department=department
end
def empname
return @name
end
def empid
return @empid
end
def empage
return @age
end
def empdeparmtnet
return @department
end
end
empobj=Employee.new
empobj.empdetails("tom","522001","28","IT")
puts(empobj.empname)
答案 0 :(得分:2)
在ruby class
中,关键字应为小写。
class Employee
def empdetails(name,empid,age,department)
@name=name
@empid=empid
@age=age
@department=department
end
def empname
return @name
end
def empid
return @empid
end
def empage
return @age
end
def empdeparmtnet
return @department
end
end
empobj=Employee.new
empobj.empdetails("tom","522001","28","IT")
puts(empobj.empname)