Skip to content

Instantly share code, notes, and snippets.

/rr.rb Secret

Created March 5, 2018 17:55
Show Gist options
  • Save anonymous/c5763312c69c8d3a5ae2ab7be9e16b20 to your computer and use it in GitHub Desktop.
Save anonymous/c5763312c69c8d3a5ae2ab7be9e16b20 to your computer and use it in GitHub Desktop.
require 'yaml'
class User
def initialize(id, student)
@id = id
@isStudent = student
# TODO eventually add other stuff such as class, school, area etc. and keep
end
def isStudent
@isStudent
end
def isTeacher
!@isStudent
end
def to_s
"In User:\n #{@id}, #{@isStudent}\n"
end
end
class Users
def initialize
@users = []
restore
end
def insertUser u
@users << u
backup
end
def userExists u
@users.include? u
end
def backup
File.open('users.yml', 'r+') { |f| f.write(@users.to_yaml) }
end
def restore
File.new('users.yml', 'w+') unless File.exists?('users.yml')
@users = YAML.load_file('users.yml')
end
end
class Conversations
def initialize()
@convos = []
end
def addConversation(teacher, student)
@convos << [teacher, student]
end
def removeConversation(t, s)
@convos.delete([t, s])
end
def conversationExists(user)
@convos.each do |t, s|
return t if (user == s) || (t == user)
end
nil
end
end
bb = Users.new
# puts bb.instance_variable_get("@users").length
bb.insertUser User.new 11, true
bb.insertUser User.new 11, true
bb.insertUser User.new 11, true
bb.insertUser User.new 11, true
bb.insertUser User.new 11, true
bb.insertUser User.new 11, true
bb.insertUser User.new 11, true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment