[Ruby] Trying to debug this error

Trying to debug this error.

#!/usr/bin/env ruby
# frozen_string_literal: true

# Created by Paul A.Gureghian in May 2020. #
# This Ruby program demos the creation of a class and the generation of instances of the class. #

# Start of program. #

# Create the class. #
class Computer
  
  @@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 Computer.get_users

    @@users

  end   
end    

# Instantiate the class. #
paul_computer = Computer.new('paul', 'monkey123')

# Call the "create" class method and create a file. #
paul_computer.create('ruby.txt')

# Print out user(s) name(s). #
puts "User(s): #{Computer.get_users}."

# End of program. #

Hi,

I’m not using Ruby, but in the “create” method or function you can’t access directly the username instance variable, I guess that you should replace
#{username} by #@username .

best regards

Yup. that was the error.

Do you know why the “initialize” method is not called during the instantiation of the class ? I’m using 'Computer.new ’ instead of ‘Computer.initialize’ .

Try replacing #{Computer.get_users} with #{paul_computer.get_users} in the last line