Skip to content

Instantly share code, notes, and snippets.

@blackwatertepes
Created March 4, 2013 18:03
Show Gist options
  • Save blackwatertepes/5084161 to your computer and use it in GitHub Desktop.
Save blackwatertepes/5084161 to your computer and use it in GitHub Desktop.
Composition
Inheritance Model
class Car
attr_reader :color, :wheels, :cost
def initialize(args)
@wheels = 4
@color = args[:color]
@cost = :respectible
end
end
class Ferarri < Car
def initialize(args)
super(args)
@cost = :expensive
end
end
class Yugo < Car
def initialize(args)
super(args)
@cost = :dirt
end
end
Composition Model
class Luxury
attr_reader :color, :wheels, :cost
def initialize(args)
@wheels = 4
@color = args[:color]
@cost = args[:cost]
end
end
class Ferarri
attr_reader :luxury
def initialize(args)
@luxury = Luxury.new({color: args[:color], cost: args[:cost]})
end
end
class Yugo
attr_reader :luxury
def initialize(args)
@luxury = Luxury.new({color: args[:color], cost: args[:cost]})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment