我正在尝试在Ruby On Rails App中创建一个User类,当我打电话时
NETWORKING::User.new(1,"Testing")
,它会返回*** ArgumentError Exception: wrong number of arguments (2 for 0)
不确定原因?
class NETWORKING::User
mattr_writer :id, :name
class << self
def initialize(id, name)
@id = id
@fullname = name
end
end
end
答案 0 :(得分:2)
class << self
除了破坏您的代码外没有任何意义。删除它:
class NETWORKING::User
attr_accessor :id, :name
def initialize(id, name)
@id = id
@fullname = name
end
end