Skip to content

Instantly share code, notes, and snippets.

@jtallant
Created July 11, 2012 23:04
Show Gist options
  • Save jtallant/3094346 to your computer and use it in GitHub Desktop.
Save jtallant/3094346 to your computer and use it in GitHub Desktop.
Ruby Getters and Setters
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