Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Instance Methods Class Error: in `new': wrong number of arguments (given 7, expected 0) (ArgumentError)

Hi I am just getting the following error: "in `new’: wrong number of arguments (given 7, expected 0) (ArgumentError)"

In app/services/quarterback.rb I have:

class Quarterback
attr_accessor :id, :firstname, :secondname, :club, :position, :price, :totalpoints,
def initialize(id, firstname, secondname, club, position, price, totalpoints)
    @id = id
    @firstname = firstname
    @secondname = secondname
    @club = club
    @position = position
    @price = price
    @totalpoints = totalpoints
end

def info
    "#{firstname} works for #{club} and has a cost of #{price}."
end

sparky = Quarterback.new('1', 'John', 'Edgar', 'Liverpool', 'Forward', '100', '38' )
puts sparky.info
end

Thanks for the help!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

That’s because you have a , at the end of line 2:

attr_accessor :id, :firstname, :secondname, :club, :position, :price, :totalpoints,

to be replaced with

attr_accessor :id, :firstname, :secondname, :club, :position, :price, :totalpoints

For a more detailed explanation as to why that error was triggered, I would suggest to have a read at this great answer: https://stackoverflow.com/a/58176158/11330290

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading