Skip to content

Instantly share code, notes, and snippets.

@vsavkin
Created August 12, 2012 18:50
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 vsavkin/3333671 to your computer and use it in GitHub Desktop.
Save vsavkin/3333671 to your computer and use it in GitHub Desktop.
Roles
class TransferringMoney
include Context
...
def transfer amount
...
end
module SourceAccount
include ContextAccssor
def transfer_out amount
raise "Insufficient funds" if balance < amount
decrease_balance amount
context.destination_account.transfer_in amount
update_log "Transferred out", amount
end
end
module DestinationAccount
include ContextAccssor
def transfer_in amount
increase_balance amount
update_log "Transferred in", amount
end
end
end
@chrisnicola
Copy link

Not sure if I'm a fan of the roles accessing the context. It feels like a bit of a boundary issue to me and it's unnecessary. Why is context.destination_account.transfer_in better than:

source_account.transfer_to(destination_account, amount)
...
def transfer_to destination, amount
  ...
  destination.receive_from(self, amount)
  ...
end

The other odd thing is both roles have the ContextAccssor mixin, but only one even uses it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment