Skip to content

Instantly share code, notes, and snippets.

@rebo
Created December 19, 2012 15:37
Show Gist options
  • Select an option

  • Save rebo/4337589 to your computer and use it in GitHub Desktop.

Select an option

Save rebo/4337589 to your computer and use it in GitHub Desktop.
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