Skip to content

Instantly share code, notes, and snippets.

View runefs's full-sized avatar

Rune Lund-Søltoft runefs

View GitHub Profile
@runefs
runefs / gist:4621229
Last active December 11, 2015 15:29
This is an example of how DCI can be done in Ruby without injecting methods into objects. It's inspired by how the Marvin compiler works, and is basically rewritting method calls on a RolePlayer into a method call on the context object when the method being cllaed is a role method. It does not work completely like marvin E.g. any access to a rol…
require 'live_ast'
require 'live_ast/to_ruby'
module Player
alias metho_missing_org method_missing
def method_missing (name, *args)
current = Context.current
raise "no current context" unless current
role_name = current.role_name
method_name = "self_#{role_name}_#{name}".to_sym
class Context
def bind(player, roleMethods)
lambda {|(*args)|
if args.length == 0 then return player end
name = args[0]
m = roleMethods[name]
if m == nil
m = player.method(name)
end
m.call *args[1..-1]
require 'alias_dci'
class A
include AliasDCI::DataObject
def foo
"a"
end
end
class C
include AliasDCI::Context, AliasDCI::DataObject