Skip to content

Instantly share code, notes, and snippets.

@allolex
Created October 14, 2015 21:52
Show Gist options
  • Save allolex/f17b542a977e72385a0e to your computer and use it in GitHub Desktop.
Save allolex/f17b542a977e72385a0e to your computer and use it in GitHub Desktop.

Revisions

  1. allolex created this gist Oct 14, 2015.
    38 changes: 38 additions & 0 deletions automobiles.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    require_relative 'talkative'

    class Vehicle
    attr_accessor :engine, :tires
    end

    class Car < Vehicle
    def initialize
    @tires = 4
    end
    end

    class Motorcycle < Vehicle
    def initialize
    @tires = 2
    end
    end

    class TelevisionCar < Car
    include Talkative
    end

    kitt = TelevisionCar.new
    p TelevisionCar.ancestors
    p TelevisionCar.superclass

    kitt.speak
    puts kitt.tires

    # c = Car.new
    # p Car.superclass
    # c.engine = "small"
    # p c.engine
    #
    # m = Motorcycle.new
    # p Motorcycle.superclass
    # m.engine = "smaller"
    # p m.engine
    5 changes: 5 additions & 0 deletions talkative.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    module Talkative
    def speak
    puts "hello"
    end
    end