Skip to content

Instantly share code, notes, and snippets.

@runefs
Created December 19, 2012 17:58
Show Gist options
  • Save runefs/4338821 to your computer and use it in GitHub Desktop.
Save runefs/4338821 to your computer and use it in GitHub Desktop.
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)
print
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