Created
January 19, 2013 23:53
-
-
Save gcao/4575876 to your computer and use it in GitHub Desktop.
DCI demonstration
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 'forwardable' | |
Data = Struct.new(:name) | |
class Role | |
extend Forwardable | |
def_delegators :@data, :name= | |
def initialize data | |
@data = data | |
end | |
def operation | |
self.name = 'name' | |
end | |
end | |
class Context | |
def initialize role | |
@role = role | |
end | |
def interaction | |
@role.operation | |
end | |
end | |
data = Data.new | |
role = Role.new(data) | |
context = Context.new(role) | |
context.interaction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment