8/8 How to call @files?


#1

Hey, how I can call @files? thanks

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 'Added!'
end

def Computer.get_users

    return @files
end

end

my_computer = Computer.new('loll', 123)

my_computer.create('lol1')
my_computer.create('lol2')
my_computer.create('lol3')

Computer.get_users

my_computer.@files


#2

One way is to add a utility method for this purpose:

  def files
      puts "Files for user #{@username} (#{@files.count})"
      @files.each { |k,v| puts "#{k} : #{v}" }
      return
  end

Then we can call it on our instance...

my_computer.files

Let us know if your find something that improves upon this. It was what I could come up with.