Skip to content

Instantly share code, notes, and snippets.

@bblimke
Created September 5, 2011 10:00
Show Gist options
  • Save bblimke/1194608 to your computer and use it in GitHub Desktop.
Save bblimke/1194608 to your computer and use it in GitHub Desktop.
DCI in Ruby
class Person
attr_reader :name
def initialize(name)
@name = name
end
end
person = Person.new("Trygve Reenskaug")
module Buyer
def buy(item)
# buying logic
end
end
module FootballPlayer
def kick_ball(ball)
# kicking ball logic
end
def run
# running logic
end
end
def FootballGameContext
person.mixin FootballPlayer
person.run
person.kick_ball(ball)
person.unmix FootballPlayer
end
def ShopContext
person.mixin Buyer
person.buy(milk)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment