5. Getting more creative - Did you add a create method to your Computer class?


#1

Hello there,

In part 5 (getting more creative), I'm facing an issue again and again and don't understand how to solve it.
Here is my code :

class Computer
@@users = {}
@files = {}

def initialize(username,password)
@username = username
@password = password
@@users[username]= password
end

def create(filename)
time=Time.now
@files[filename]=time
end

end

Could you please help me on this subject? The error message is : "Oops, try again. Did you add a create method to your Computer class?"

Many thanks :smile:


#2

I had the same problem.
I could solve the problem by reseting the code and then readding the create function again.

I hope that this will also work for you


#3

You need two @@ on each of your files

@files should be @@files (Lines 3 and 11)


#4

Here is the code that worked for me:

class Computer
@@users ={}
@@files ={}

def initialize (username, password)
    @username = username
    @password = password

    @@users[username] = password
end
def create(filename)
   time =Time.now
   @@files[filename] =time
   puts "A new file was created!"

end
end


Hope it works!


#5

this worked for me
class Computer
@@users = {}
def initialize (username,password)
@@users[username] = password
@username = username
@password = password
@files = {}

    def create (filename)
        time = Time.now
        @files[filename]=time
        puts"Congratulations, your new file have been created"
    end
end

end


#6

This. Here you are defining an instance variable(single @) for this class. Rather than an overall class variable(double @@).


#7

Could you give me an extended explanation of why using an @?


#8

Worked for me too! :clap: