Created
October 16, 2019 08:38
-
-
Save juliends/fd8e64a58c3bd8d4a08b50e63f9a1d51 to your computer and use it in GitHub Desktop.
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 # => UpperCamelCase | |
# attr_reader :color, :brand | |
# attr_writer :color | |
attr_accessor :color, :brand | |
def initialize(color, brand) # => constructor stores the data/state | |
@color = color | |
@brand = brand | |
@engine_started = false # => instance variable | |
end | |
# => behavior | |
# def color | |
# return @color | |
# end | |
# def color=(color) | |
# @color = color | |
# end | |
def engine_started? | |
@engine_started | |
end | |
def start_engine | |
start_fuel_pump | |
init_spark_plug | |
@engine_started = true | |
end | |
private # => Can't be called on an instance | |
def start_fuel_pump | |
# => Complex procedure | |
end | |
def init_spark_plug | |
end | |
end | |
blue_car = Car.new("blue", "Volvo") | |
p blue_car.color | |
blue_car.color = "green" | |
p blue_car.color | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment