Skip to content

Instantly share code, notes, and snippets.

@fearofcode
Created February 21, 2013 04:36
Show Gist options
  • Save fearofcode/5002102 to your computer and use it in GitHub Desktop.
Save fearofcode/5002102 to your computer and use it in GitHub Desktop.
Simple Ruby OOP example
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