Law of Demeter

I think you can to create a new object like this :

class AccountCharger
  def initialize(account)
    @credit_card = account.credit_card
    @plan_price = account.plan_price
  end

  def charge
    @credit_card.charge(@plan_price) if @credit_card.valid?
  end
end

And use it like this :

class CreditCardsControlller < ApplicationController
  def charge_for_plan
    AccountCharger.new(current_user.account).charge
  end
end

Am I right @jferris and @benorenstein?

1 Like