不创建类对象 - Ruby on Rails

时间:2018-03-02 21:32:12

标签: ruby-on-rails ruby

我正在尝试在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

1 个答案:

答案 0 :(得分:2)

class << self除了破坏您的代码外没有任何意义。删除它:

class NETWORKING::User 
  attr_accessor :id, :name

  def initialize(id, name)
    @id = id
    @fullname = name
  end
end