Skip to content

Instantly share code, notes, and snippets.

@codetombomb
Last active September 16, 2020 04:47
Show Gist options
  • Save codetombomb/55595c835c959babcc86bc256301e273 to your computer and use it in GitHub Desktop.
Save codetombomb/55595c835c959babcc86bc256301e273 to your computer and use it in GitHub Desktop.
Adding class methods
class Car
attr_accessor :color, :year, :make, :model
@@all = []
def initialize(color, year, make, model)
@color = color
@year = year
@make = make
@model = model
@@all << self
end
def get_vin
puts self
end
def years_old
Time.now.year - self.year
end
def self.all
@@all
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment