Skip to content

Instantly share code, notes, and snippets.

@Leejojo
Created June 27, 2016 15:14
Show Gist options
  • Save Leejojo/6473df1d12598190f4832d699606c861 to your computer and use it in GitHub Desktop.
Save Leejojo/6473df1d12598190f4832d699606c861 to your computer and use it in GitHub Desktop.
Week 2, Day 1 Notes : CLASSES
class Car
def initialize(model, colour)
@model = model
@colour = colour
end
end
class Suv < Car
attr_accessor :model, :offroad_mode, :colour
def initialize(model, colour)
super
@offroad_mode = false
end
def start_offroading
@offroad_mode = true
end
end
toyota = Suv.new('Toyota Rav4', 'blue')
toyota.start_offroading
puts toyota.offroad_mode
toyota.offroad_mode = false
puts toyota.offroad_mode
class Furniture
def initialize(material, colour, num_legs = 4)
@material = material
@colour = colour
@num_legs = num_legs
end
end
class Chair < Furniture
def initialize(material, colour = 'gray')
super
# super(material, colour)
end
end
class MetalicChair < Chair
def initialize(colour = 'gray')
super('metal', color)
end
end
class Table < Furniture
def initialize(material, colour = 'gray', num_legs = 5)
super
end
end
class Sofa < Furniture
def initialize(m, c = 'red', sofa_bed = false)
super(m, c, 0)
@sofa_bed = sofa_bed
end
def is_sofa_bed?
@sofa_bed
end
end
class SuperComforterSofaExterme < Sofa
def initialize(mat, col)
super(mat, col, true)
# @sofa_bed = sofa_bed
end
end
puts chair_1 = Chair.new('wood')
puts chair_2 = Chair.new('wood', 'blue')
puts sofa_bed = SuperComforterSofaExterme.new('wood', 'blue')
puts Table.new('metal')
puts Table.new('metal', nil, 6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment