Created
November 15, 2018 19:18
-
-
Save kodyclemens/a6cc36ac8a65a41c459fa5b38ce74a12 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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