Ruby lesson: 5. Getting more creative

Below is my code for lesson 5. Getting more creative.

It returns: nil (up to this stage), but … in lesson 6. Who’er the users? it returns:

The filename films.txt was created by Edgar at 2016-08-05 14:04:24 +0000
The filename cars.txt was created by Michael at 2016-08-05 14:04:24 +0000

My code for lesson 5:

class Computer

@@users = {}

def initialize(username, password)
    @username = username
    @password = password 
    @files = {}
    @@users[username] = password

def create(filename)
    time =
    @files[filename] = time
    puts "The filename #{filename} was created by #{@username} at #{time}"


Is this because #{filename} and #{@username} are still empty in lesson 5? If yes, should it not at least put:

The filename nil was created by nil at 14:04:24 +0000

Your code prints nothing. Not nil, nothing.
You’re not invoking that method, program control never reaches that line.

I don’t understand … I get nil in the console.

Or do you mean that the program never reaches puts statement, so the #{filename} and the #{@username} never get an assignment? And so the puts statement doesn’t print?

The class is created and the methods are created. Then your program is done. That is all it does. They are never instantiated/invoked. Your code prints nothing. The text in the console is not from your code, because your code doesn’t execute any instruction to do printing.

Thank you, ionatan, for taking the time. That is wonderful. I totally get it now. :relaxed:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.