Skip to content

Instantly share code, notes, and snippets.

@gcao
Created January 19, 2013 23:53
Show Gist options
  • Save gcao/4575876 to your computer and use it in GitHub Desktop.
Save gcao/4575876 to your computer and use it in GitHub Desktop.
DCI demonstration
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