Skip to content

Instantly share code, notes, and snippets.

Created October 19, 2016 17:54
Show Gist options
  • Save anonymous/46da980e46f81061c18a7fa05e2e3b5c to your computer and use it in GitHub Desktop.
Save anonymous/46da980e46f81061c18a7fa05e2e3b5c to your computer and use it in GitHub Desktop.
#In my program, I can create a simulated user session.
#The operator begins in a looped Shell class to perform commands like choosing a user (the select method below).
#Choosing a user begins a looped User class instance and assigns it to a @session variable that exists within a Shell class.
#The operator gains add, delete powers until he chooses to again start another new instance of Shell.
#I lose the ability to maintain a single Shell and dedicated users, like an @Joe = User.new("joe").
#When you switch from Joe to Bob, you begin each user anew. Same with the Shell.
#The only way a user is defined is by his associated files (I link the name "Joe" to a joe.file).
#How do you typically handle users? Is my approach off the deep end?
#I call a few outside methods here within the select method
#this method:
#prints lines in file, @userlist, that contains existing usernames (bob, joe, etc.; 1 per line)
#asks person to select existing user
#if selection matches existing user, begins a session
def select
puts "\nSelect user (type name): "
list_lines(@userlist)
user = gets.chomp
if list_include?(@userlist, user)
session = User.new(user)
session.shell
else
select
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment