Skip to content

Commit

Permalink
Exercise 42: Is-A, Has-A, Objects, and Classes
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowflash2041 committed Oct 5, 2022
1 parent d7faff2 commit 140193b
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions ex42.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Animal is-a object look at the extra credit
class Animal
end

# ??
class Dog < Animal

def initialize(name)
# ??
@name = name
end
end

# ??
class Cat < Animal

def initialize(name)
# ??
@name = name
end
end

# ??
class Person

def initialize(name)
# ??
@name = name

# Person has-a pet of some kind
@pet = nil
end

attr_accessor :pet
end

# ??
class Employee < Person

def initialize(name, salary)
# ?? hmm what is this strange magic?
super(name)
# ??
@salary = salary
end

end

# ??
class Fish
end

# ??
class Salmon < Fish
end

# ??
class Halibut < Fish
end


# rover is-a Dog
rover = Dog.new("Rover")

# ??
satan = Cat.new("Satan")

# ??
mary = Person.new("Mary")

# ??
mary.pet = satan

# ??
frank = Employee.new("Frank", 120000)

# ??
frank.pet = rover

# ??
flipper = Fish.new()

# ??
crouse = Salmon.new()

# ??
harry = Halibut.new()

0 comments on commit 140193b

Please sign in to comment.