Just curios. on the below, why does calling the first 2 work, but the 3rd does not. Do you always have to pass through the “initialization” method when calling a method in a class?
WORKS
my_computer.create(“TEST 1”)
WORKS
Computer.new(“test”, 123).create(“TEST 2”)
DOESNT WORK
Computer.create(“TEST 3”)
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 "Created #{filename} at #{time}"
end
def Computer.get_users
return @@users
end
end
my_computer = Computer.new("Tr", 123)