Created
December 19, 2012 15:50
-
-
Save rebo/4337722 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 "I'm using my finger to point at #{thing}" | |
| end | |
| end | |
| class DonutStreetVendorAtBlackedOutTraficlight | |
| include AliasDCI::Context | |
| role :policeman do | |
| def point(thing) | |
| p "I'm using my police batton to point at #{thing}" | |
| end | |
| end | |
| role :customer do | |
| contract :point | |
| def pay_for_donut | |
| p "I am paying for the donut" | |
| end | |
| end | |
| def initialize(a_person, another_person) | |
| assign_named_roles(:policeman => a_person, :customer => another_person) | |
| end | |
| def guide_traffic_and_have_customer_buy_a_donut | |
| in_context do | |
| policeman.point("Cars") | |
| r_customer.point("a Donut") # have to use "r_rolename" as policeman implements #point. | |
| end | |
| end | |
| end | |
| bob = Person.new | |
| DonutStreetVendorAtBlackedOutTraficlight.new(bob, bob).guide_traffic_and_have_customer_buy_a_donut | |
| # => nil | |
| # >> "I'm using my police batton to point at Cars" | |
| # >> "I'm using my finger to point at a Donut" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment