Skip to content

Instantly share code, notes, and snippets.

@rosylilly
Last active December 10, 2015 02:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rosylilly/285ec33e6cfceb0ba0cf to your computer and use it in GitHub Desktop.
Save rosylilly/285ec33e6cfceb0ba0cf to your computer and use it in GitHub Desktop.
Where is Logics?
class User
def buy_item(item)
self.purchases.create(item: item)
end
end
class PurchasesController
def create
item = Item.find(params[:item_id])
current_user.purchases.create(item: item)
end
end
class BuyItemContext
def initialize(user, item)
@user = user
@item = item
@user.extend(Customer)
end
def process
@user.buy(item)
end
end
module Customer
def buy(item)
self.purchases.create(item: item)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment