Created
December 19, 2012 17:58
-
-
Save runefs/4338821 to your computer and use it in GitHub Desktop.
This file contains 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 A | |
include AliasDCI::DataObject | |
def foo | |
"a" | |
end | |
end | |
class C | |
include AliasDCI::Context, AliasDCI::DataObject | |
role :y | |
role :z do | |
def foo | |
"z" | |
end | |
end | |
def initialize(some_t, some_k) | |
assign_named_roles(:y => some_t, :z => some_k) | |
end | |
def print | |
in_context do | |
puts "foo of y " + (y.foo.to_s) | |
puts "foo of z " + (z.foo.to_s) | |
end | |
end | |
def foo | |
"context" | |
end | |
def rebind(a) | |
initialize(a,self) | |
initialize(self,a) | |
end | |
end | |
def do_it(some_t, some_k) | |
c = C.new(some_t, some_k) | |
c.print | |
c.rebind(some_t) | |
c.print | |
end | |
class DataObject | |
include AliasDCI::DataObject | |
end | |
a = A.new | |
do_it(a, a) | |
#outputs | |
#foo of y z | |
#foo of y z | |
#each object is only playing one role | |
#foo of y z | |
#foo of y z | |
#again one role for each object | |
#foo of y z | |
#foo of y z | |
#should have been | |
#foo of y a | |
#foo of y z | |
#foo of y a | |
#foo of y z | |
#foo of y context | |
#foo of y z |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment