Created
December 19, 2012 10:42
-
-
Save rebo/4335853 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'alias_dci' | |
| class Person | |
| include AliasDCI::DataObject | |
| def point(thing) | |
| p "As a #{dci_roles.last||'Regular Person'} I am using my finger to point at #{thing}" | |
| end | |
| end | |
| class TrafficGuidance | |
| include AliasDCI::Context | |
| role :policeman do | |
| def point(thing) | |
| p "As a #{dci_roles.last} I am using my police batton to point at #{thing}" | |
| end | |
| end | |
| def initialize(person) | |
| assign_named_roles(:policeman => person) | |
| end | |
| def guide_traffic_then_buy_a_donut | |
| in_context do | |
| policeman.point("Cars") | |
| BuyADonut.new(policeman).get_donut | |
| end | |
| end | |
| end | |
| class BuyADonut | |
| include AliasDCI::Context | |
| role :customer do | |
| contract :point | |
| def pay_for_donut | |
| p "As a #{dci_roles.last} I am paying for the donut" | |
| end | |
| end | |
| def initialize(person) | |
| assign_named_roles(:customer => person) | |
| end | |
| def get_donut | |
| in_context do | |
| customer.point("Tasty Chocolate Donut") | |
| customer.pay_for_donut | |
| end | |
| end | |
| end | |
| bob = Person.new | |
| bob.point("a cat") | |
| TrafficGuidance.new(bob).guide_traffic_then_buy_a_donut | |
| # >> "As a Regular Person I am using my finger to point at a cat" | |
| # >> "As a TrafficGuidance::Policeman I am using my police batton to point at Cars" | |
| # >> "As a BuyADonut::Customer I am using my finger to point at Tasty Chocolate Donut" | |
| # >> "As a BuyADonut::Customer I am paying for the donut" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment