Skip to content

Instantly share code, notes, and snippets.

@bblimke
Created September 5, 2011 10:28
Show Gist options
  • Save bblimke/1194652 to your computer and use it in GitHub Desktop.
Save bblimke/1194652 to your computer and use it in GitHub Desktop.
DCI and Inheritance
class Vehicle
attr_reader: speed
end
class Ship < Vehicle
attr_accessor: anchor
end
class Airplane < Vehicle
attr_accessor :wings
end
module Motorized
def start_engines
#start engine logic
end
end
module Flyable
def take_off
#take off logic
end
end
module Sailable
def sail
#sail logic
end
end
plane = Airplane.new
ship = Ship.new
def RunwayContext
plane.mixin Motorized
plane.mixin Flyable
plane.start_engines
plane.take_off
end
def WaterContext
ship.mixin Motorized
ship.mixin Sailable
ship.start_engines
ship.sail
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment