Skip to content

Instantly share code, notes, and snippets.

@yock

yock/user.rb Secret

Last active December 18, 2015 00:48
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 yock/a7f55af369dfb8716e96 to your computer and use it in GitHub Desktop.
Save yock/a7f55af369dfb8716e96 to your computer and use it in GitHub Desktop.
Refactored user model
class User < ActiveRecord::Base
## Omitting Rails stuff...
attr_accessor :service, :cc_token
def pay(amount)
service.pay(amount, external_id: self.external_id)
end
def register
self.external_id = service.register(self.cc_token, name: self.name, email: self.email)
self.save
end
def service
@service ||= GatewayService
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment