Skip to content

Instantly share code, notes, and snippets.

@kodyclemens
Created November 15, 2018 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kodyclemens/a6cc36ac8a65a41c459fa5b38ce74a12 to your computer and use it in GitHub Desktop.
Save kodyclemens/a6cc36ac8a65a41c459fa5b38ce74a12 to your computer and use it in GitHub Desktop.
require "pry"
class Appointment
attr_accessor :date, :patient, :doctor
@@all = []
def initialize(date, patient, doctor)
@date = date
@patient = patient
@doctor = doctor
@@all << self
end
def self.all
@@all
end
end
class Doctor
attr_accessor :name
def initialize(name)
@name = name
@@all << self
end
def new_appointment(patient, date)
# given a date and a patient, creates a new appointment
Appointment.new(date, patient, self)
end
end
class Patient
attr_accessor :name
@@all = []
def initialize(name)
@name = name
@@all << self
end
def new_appointment(doctor, date)
Appointment.new(date, self, doctor)
end
end
# Use the appointment class to make a new appointment.
johnson = Doctor.new("Dr. James Johnson")
kody = Patient.new("Kody Clemens")
first_appointment = Appointment.new(Time.now.strftime("%Y-%m-%d"), kody, johnson)
binding.pry
# Use the doctor new_appointment instance method to create an appointment, given a patient and a date.
carl = Patient.new("Carl Nicholson")
johnson.new_appointment(carl, Time.now.strftime("%Y-%m-%d"))
binding.pry
# Use the patient new_appointment instance method to create an appointment, given a doctor and a date.
weaver = Doctor.new("Dr. Alex Weaver")
kody.new_appointment(Time.now.strftime("%Y-%m-%d"), weaver)
binding.pry
# The last line in the ruby file cannot be binding.pry. You can ignore the puts "foo".
puts "foo"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment