Skip to content

Instantly share code, notes, and snippets.

@Alacrity01
Created April 25, 2019 19:14
Show Gist options
  • Save Alacrity01/21a7317746f06066fdee8135e73c4360 to your computer and use it in GitHub Desktop.
Save Alacrity01/21a7317746f06066fdee8135e73c4360 to your computer and use it in GitHub Desktop.
Week 1, Day 4
Week 1, Day 4.txt
composition (if it's a class), module (if not a class)--a list of behaviors to mix in to other classes, mix ins (act of using module)
Modules can be very useful for creating DRY code (removes redundancy of code)
Since modules are a list of behaviors, some coders believe it should not include redundant initialize method attributes (however, some coders do include the initialize method). An alternative is to create a parent class with initialize that includes the module of behaviors, then have the subclasses inherit from the parent class.
Ex:
module Behaviors
#some methods
end
class Vehicle
includes Behaviors™
def initialize
command + option + 2 Will create two side by side screens.
command + option + shift + 2 Will create two screens, top and bottom.
command + option + 5 Will create 4 screens (quadrants)
require "./employee.rb"
require "./reportable.rb"
^ Lines at top of file that say current Ruby file will include contents of employee.rb, etc., which are in the same directory (specified by the ./ )
Modules can be used to encapsulate classes into a group. Ex: Many people may make an Employee class, so you might put that within a module called Actualize. That way it becomes *your* Employee class and can be distinguished from someone else's.
Creating an object using encapsulation is different: employee_1 = Actualize::Employee.new(attributes)
Square breathing:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment