1.7 Instantiation Nation - wrong number of arguments


Here's my code:

class Computer
def initialize(username, password)
@username = username
@password = password
@files = {}
@@users = {}
def initialize
@@users[username] = password
def create(filename)
time = Time.now
@files[filename] = time
puts "New file #{filename} was created by #{username} at #[time}."
def Computer.get_users
return @@users

my_computer = Computer.new("ScoGro", "1234")

I did fine on all the exercises before this one, but now I'm getting the error "wrong number of arguments (2 for 0) - which seems weird, since the Computer class calls for two arguments.



You have two initialize methods.


Hm. Indeed I do. But that wasn't a problem in the exercises before this one - the only thing I added this time around was the last line:

my_computer = Computer.new("ScoGro", "1234")

Everything else, in exactly the same order, had been in exercise 1.6 and it passed.


Probably because in the previous exercise there's no instantiation of our class (no object is actually created, we only define the class), so the initialize method is never called and therefore Ruby doesn't know that there's a conflict.

Have you tried removing the initialize method not taking any parameter?


Yes, I did, and that fixed it.

I'm still irked that it worked in the previous exercise, though. :stuck_out_tongue: