Created
December 19, 2012 15:37
-
-
Save rebo/4337589 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 Player | |
| include AliasDCI::DataObject | |
| def foo(str) | |
| str + "b" | |
| end | |
| def to_string | |
| "a" | |
| end | |
| end | |
| class Context | |
| include AliasDCI::Context | |
| role :a do | |
| contract :to_string | |
| def foo | |
| b.frob(a.to_string) | |
| end | |
| end | |
| role :b do | |
| contract :foo | |
| def frob(str) | |
| r_b.foo(str) # force role b's object's instance method #foo to be called. | |
| end | |
| end | |
| def initialize(a_player, another_player) | |
| assign_named_roles(:a => a_player, :b => another_player) | |
| end | |
| def call | |
| in_context do | |
| a.foo | |
| end | |
| end | |
| end | |
| player = Player.new | |
| puts Context.new(player, player).call | |
| # >> ab |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment