8. virtual computer


#1

Is there something wrong with my code? Why isn't anything showing up on the console?
class Computer
@@users = {}
def initialize (username, password)
@username = username
@password = password
@files = {}
@@users[username] = password
end
def create (filename)
@time = Time.now
@files[filename] = time
puts "A new file #{filename} by #{username} was created at #{time}."
end
def Computer.get_users
return @@users
end
end
my_computer = Computer.new("kiddo", 123)


#2

To the best of my understanding you haven't modified the object 'my_computer'.

If you want it to display the puts statement in your create(filename) method you would need to assign the object 'my_computer' the method 'create'.

On a separate line write the following

my_computer.create("whatever filename you want")

Also one more thing. Inside your create method where your puts statement is, you should have an '@' sign in front of 'username' ( #{@username} ) as it will call whatever instance of username your object my_computer has. Without the '@' sign it's an unassigned variable.


#3

Thank you so much! I will try your suggestions.