Created
July 11, 2012 23:04
-
-
Save jtallant/3094346 to your computer and use it in GitHub Desktop.
Ruby Getters and Setters
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
class Prescription | |
# setter for rx_name | |
def rx_name=(value) | |
@rx_name = value | |
end | |
# setter for patient name | |
def patient_name=(value) | |
@patient_name = value | |
end | |
# setter for drip count | |
def drip_count=(value) | |
@drip_count = value | |
end | |
# getter for rx name | |
def rx_name | |
puts @rx_name | |
end | |
# getter for patient name | |
def patient_name | |
puts @patient_name | |
end | |
# getter for drip count | |
def drip_count | |
puts @drip_count | |
end | |
end | |
rx1 = Prescription.new | |
rx1.rx_name = "Amoxicillin" | |
rx1.patient_name = "Joe Dirt" | |
rx1.drip_count = 30 | |
rx1.rx_name # => Amoxicillin | |
rx1.patient_name # => Joe Dirt | |
rx1.drip_count # => 30 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment