-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomputer.rb
More file actions
38 lines (31 loc) · 842 Bytes
/
computer.rb
File metadata and controls
38 lines (31 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env ruby
class Computer
@@users = {}
def initialize username, password
@username = username
@password = password
@files = {}
@@users[username] = password
end
def create_file filename
@files[filename] = Time.now
puts "New file \"#{filename}\" created by #{@username} at #{Time.now}."
end
def delete_file filename
@files.delete filename
puts "File \"#{filename}\" deleted by #{@username} at #{Time.now}."
end
def to_s
"#{@username}'s files: #{@files}"
end
def Computer.get_users
@@users
end
end
my_computer = Computer.new "Steve", "omgbestpasswordever"
my_computer.create_file "notes.txt"
my_computer.create_file "game.c"
my_computer.create_file "index.html"
my_computer.delete_file "index.html"
puts Computer.get_users
puts my_computer