Last active
September 16, 2020 04:47
-
-
Save codetombomb/55595c835c959babcc86bc256301e273 to your computer and use it in GitHub Desktop.
Adding class methods
This file contains hidden or 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 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