5. Getting More Creative


#1



https://www.codecademy.com/courses/ruby-beginner-en-X5wcR/0/5?curriculum_id=5059f8619189a5000201fbcb#


It turns nil only. I can't see the message which I wrote as puts "New file #{filename} was created by #{@username} at #{time}". What is wrong here? Can someone give me any idea?


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


#2

We would not write this directly in the code. This is a helper method for use by an instance.

serra = Computer.new("Serra", 1234)
serra.create("my_new_file.txt")

Output

my_new_file.txt was created by Serra at 2016-07-26 17:21:59 +0000.
nil

#3

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