Skip to content

Instantly share code, notes, and snippets.

@arthur-littm
Created October 14, 2020 09:48
Show Gist options
  • Save arthur-littm/994d06c746d88a4a4552e6d5186b7ccd to your computer and use it in GitHub Desktop.
Save arthur-littm/994d06c746d88a4a4552e6d5186b7ccd to your computer and use it in GitHub Desktop.
# class Car
# car.rb
# class SportsCar
# sports_car.rb
class Car
attr_accessor :color
# color, the fact that the engine is started or not
# DATA
def initialize(color) # called when doing .new
# instance variable
@color = color
@engine_started = false
end
# BEHAVIOR
def engine_started?
return @engine_started
end
def start
# spark the engine
spark_engine()
# fuel_pump_starting
fuel_pump()
# ignition
ignition()
# 100 lines of code
@engine_started = true
end
# same as
# attr_reader :color
# def color
# return @color
# end
# attr_writer :color
# def color=(new_color)
# @color = new_color
# end
private
def spark_engine()
puts "Engine spark!"
end
def fuel_pump()
puts "Fuel pump!"
end
def ignition()
puts "Ignition!"
end
end
# require 'pry-byebug'
def full_name(first_name, last_name)
first = first_name.capitalize
# binding.pry
last = last_name.capitalize
full = "#{first} #{last}"
return full
end
# call the method
puts full_name('arthur', 'littmann')
# binding.pry
puts "Program finished"
# Top of the file where you want to debug
# require 'pry-byebug'
# Put breakpoints in your code
# binding.pry
# In the console
# next / continue
# require -> NOT YOUR CODE
require_relative 'car'
# => New instance of the class Car
my_car = Car.new('red')
my_car.start()
# p my_car
# # your_car = Car.new('blue')
# # "My car is on" / "My car is off"
# if my_car.engine_started? == true
# puts "The car is started!"
# else
# puts "The car is off!"
# end
# my_car.start()
# if my_car.engine_started? == true
# puts "The car is started!"
# else
# puts "The car is off!"
# end
# # My car is X color
# puts "My car is #{my_car.color}"
# # ??
# my_car.color = 'blue'
# puts "My car is #{my_car.color}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment