Created
July 11, 2014 23:24
-
-
Save gpherguson/9e27538cfb626ca8cb9c to your computer and use it in GitHub Desktop.
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 Car | |
attr_accessor :brand, :year, :model | |
def initialize(brand=nil, year=nil, model=nil) | |
@brand = brand | |
@year = year | |
@model = model | |
end | |
end | |
first_car = Car.new | |
first_car.brand = 'Toyota' # assignment | |
first_car.brand # => "Toyota" # get value | |
first_car.year = 1997 # assignment | |
first_car.year # => 1997 # get value | |
first_car.model = 'Corolla' # assignment | |
first_car.model # => "Corolla" # get value | |
second_car = Car.new('Subaru', 2005, 'Impressa') # assign all at once | |
second_car.brand # => "Subaru" # get value | |
second_car.year # => 2005 # get value | |
second_car.model # => "Impressa" # get value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment