Created
February 21, 2013 04:36
-
-
Save fearofcode/5002102 to your computer and use it in GitHub Desktop.
Simple Ruby OOP example
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 RentalCar | |
attr_accessor :miles_travelled | |
def check_maintenance | |
if @miles_travelled > 60000 | |
puts "Give it a tuneup!" | |
end | |
end | |
end | |
car1 = RentalCar.new | |
car1.miles_travelled = 100000 | |
car2 = RentalCar.new | |
car2.miles_travelled = 0 | |
car1.check_maintenance # prints 'Give it a tuneup!' | |
car2.check_maintenance # prints nothing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment