Skip to content

Instantly share code, notes, and snippets.

@gpherguson
Created July 11, 2014 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gpherguson/9e27538cfb626ca8cb9c to your computer and use it in GitHub Desktop.
Save gpherguson/9e27538cfb626ca8cb9c to your computer and use it in GitHub Desktop.
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