Skip to content

Instantly share code, notes, and snippets.

@barangerbenjamin
Created April 18, 2018 09:40
Show Gist options
  • Save barangerbenjamin/f63eca289dc7fc398695ae212cfa145c to your computer and use it in GitHub Desktop.
Save barangerbenjamin/f63eca289dc7fc398695ae212cfa145c to your computer and use it in GitHub Desktop.
class Car
def initialize(color)
@color = color
@engine_started = false
end
# allow you to read instance variable
def color
return @color
end
# shortcut for reading instance variable
attr_reader :engine_started, :color
# modify state of instace variable
def color=(color)
@color = color
end
# shortcut for modifying an instance variable
attr_writer :color
# shortcut for attr_reader && attr_writer
attr_accessor :color, :engine_started
# calls private methods not in the public interface of this class
def start
ignit
makes_a_noise
@engine_started = true
end
private #Everything under is in the private interface of this class, not available in the outside world
def ignit
puts "Ignit"
end
def makes_a_noise
puts "vroom vroom"
end
end
require "pry-byebug" #require the pry-byebug gem
def full_name(first, last)
first_name = first.capitalize
binding.pry # breakpoint to indicate where the program is gonna pause
last_name = last.capitalize
name = "#{first_name} #{last_name}"
return name
end
full_name("bar", "ben")
# keywords for pry-bye bug :
# next : execute the next line
# continue: execute the code until the next breakpoint or the end of the method
class SportsCar
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment