Where does .getusers reside or is it part of the naming of the method, Machine?


#1




It doesn't behave incorrectly, I just have a question on how methods can be thrown together and where some of them come from.


class Machine
  @@users = {}
  
  def initialize(username, password)
    @username = username
    @password = password
    @@users[username] = password
    @files = {}
  end
  
  def create(filename)
    time = Time.now
    @files[filename] = time
    puts "#{filename} was created by #{@username} at #{time}."
  end
  
  def Machine.get_users
    @@users
  end
end

my_machine = Machine.new("eric", 01234)
your_machine = Machine.new("you", 56789)

my_machine.create("groceries.txt")
your_machine.create("todo.txt")

puts "Users: #{Machine.get_users}"


#2

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