I'm using a similar trick in maroon and Jim is in his Ruby dijkstra example. I had the exact same objection that you do, that not all roles are mapped together and would like to improve the syntax. I do have an idea of what the syntax should be for maroon but haven't gotten that far yet.
the same can easily be accomplished by a nested context but the instantiation of a new object might be a problem if you have a lot of element for that reason I'd like to avoid nested context in maroon. I would however love if the syntax made it clear that the role was only available in a given scope.
Currently this is how you'd do
role :method do
def is_private
end
end
def my_interaction
my_collection.select do |e|
bind :e => :method
method.is_private?
end
end
notice the bind in the line in bold. THat's telling marron that in this block the object identified by e is playing the role method
the change I want to make is something like
def my_interaction
my_collection.select do |e|
bind :e => role :method do
def is_private
end
end
method.is_private?
end
end
That is defining the role as part of the block and potentially (As above) as part of the bind syntax (The call to bind and the argument(s) are all transformed before the actual execution of the context/block)
-Rune