7. Instantiation Nation!


#1

help! this is my code:

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

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

and it says:
undefined local variable or method `username' for Context:Computer:Class

Thanks!


#2

Hi this part

@@users[username] = password

should be inside the def initialize()


#3

Thanks a lot!:slight_smile:


#4

class Computer
@@users = {}
def Computer.get_users
@@users
end
def initialize(username,password)
@username = username
@password = password
@files = {}
@@users[username] = password
def create (filename)
time = Time.now
@files[filename]=time
puts"Congratulations, your new file have been created"
end

end
my_computer = Computer.new("hi",35)
i hink my code is right but still.........i think there is a problem...whats that?


#5

Hi you didn't closed that def initialize(username,password) with the end