From 7ccaa95e9038ae229c91929f7ad09a8f81f5f5ef Mon Sep 17 00:00:00 2001 From: Lance Lakey Date: Sat, 7 Apr 2012 22:19:17 -0500 Subject: [PATCH] initial commit ex45 --- ex45.rb | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100755 ex45.rb diff --git a/ex45.rb b/ex45.rb new file mode 100755 index 0000000..65e189f --- /dev/null +++ b/ex45.rb @@ -0,0 +1,95 @@ +#!/usr/bin/env ruby + +## Animal is-a object (yes, sort of confusing) look at the extra credit +class Animal + +end + +## Dog is-a Animal +class Dog < Animal + + def initialize(name) + ## dog has-a name + @name = name + end + +end + +## Cat is-a Animal +class Cat < Animal + + def initialize(name) + ## cat has-a name + @name = name + end + +end + +## Person is-a object +class Person + + attr_accessor :pet + + def initialize(name) + ## person has-a name + @name = name + + ## Person has-a pet of some kind + @pet = nil + end + +end + +## Employee is-a Person +class Employee < Person + + def initialize(name, salary) + ## ?? hmm what is this strange magic? + super(name) + ## employee has-a salary + @salary = salary + end + +end + +## Fish is-a Object +class Fish + +end + +## Salmon is-a Fish +class Salmon < Fish + +end + +## Halibut is-a Fish +class Halibut < Fish + +end + +## rover is-a Dog +rover = Dog.new("Rover") + +## satan is-a Cat +satan = Cat.new("Satan") + +## mary is-a Person +mary = Person.new("Mary") + +## mary has-a cat +mary.pet = satan + +## frank is-a employee +frank = Employee.new("Frank", 120000) + +## frank has-a dog +frank.pet = rover + +## flipper is-a fish +flipper = Fish.new + +## crouse is-a salmon +crouse = Salmon.new + +## harry is-a halibut +harry = Halibut.new