■
DCIについて言及するほど知識がなく、年末PoEAAを読もうと思っているところですが、Railsではこのように書けたら嬉しいのではないだろうかというのを思いついた。
class PurchaseController < ApplicationController def create @purchase = context(:shopping, current_user, Item.find(params[:id]) do |user, item| user.purchase(item) end respond_with(@purchase) end end class ShoppingContext < Context:Base def initialize(user, item) @user = user.extend(CustomerRole) @item = item end end module CustomerRole def purchase(item) end end