Skip to content

Instantly share code, notes, and snippets.

@arthur-littm
Created October 11, 2017 09:38
Show Gist options
  • Save arthur-littm/5e82614344e1f121b7065e2e9e1a8db8 to your computer and use it in GitHub Desktop.
Save arthur-littm/5e82614344e1f121b7065e2e9e1a8db8 to your computer and use it in GitHub Desktop.
# car.rb -> lower_snake_case
class Car # UpperCamelCase
attr_reader :engine_started, :brand
attr_accessor :colour
def initialize(colour, brand = "Mini") # constructor
@colour = colour
@engine_started = false
@brand = brand
end
def start
spark_plug_firing()
electrical_motor()
aircon_starting()
@engine_started = true
end
private
def spark_plug_firing()
# 10 lines
end
def electrical_motor()
# 10 lines
end
def aircon_starting()
# 10 lines
end
# def colour=(name_of_colour)
# @colour = name_of_colour
# end
end
require_relative 'car'
my_car = Car.new("red")
# Instantiate a new car
puts "I am starting my car"
my_car.start
# calling the instance method `start` on my instance of Car
puts "My car is now #{my_car.engine_started ? 'on' : 'off'}"
# accessing the instance variable from my instance of Car
puts "Car is #{my_car.colour}"
# accessing the instance variable from my instance of Car
puts "My car is a #{my_car.brand}"
# accessing the instance variable from my instance of Car
puts "I want to change the colour of my car"
my_car.colour = gets.chomp
# Getting the user input for new color
my_car.colour
# setting a new value to my instance variable `colour`
puts "My car is now #{my_car.colour}"
# accessing the instance variable from my instance of Car
def fullname(first,last)
first_name = first.capitalize
last_name = last.capitalize
fullname = "#{first_name} #{last_name}"
return fullname
end
puts fullname('aleX', 'BeNoIT')
# PRY-BYEBUG
# 1. gem install pry-byebug (once)
# 2. require 'pry' or 'pry-byebug'
# 3. place breakpoints with `binding.pry`
# `next` -> execute the next line only
# `continue` -> continue to next breakpoint or the end of my program
# 4. remember to remove breakpoints
class SportsCar
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment