-
-
Save davetron5000/f7e86fd909b26186b420d9b79cae0e5d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ChargeCustomer | |
def charge!(customer:, amount:, note:) | |
# do something | |
end | |
end | |
class ChargeParams | |
def initialize(order) | |
@order = order | |
end | |
def to_hash # this is the magic of double-splat | |
{ | |
customer: @order.customer, | |
amount: @order.total, | |
note: "Purchased #{@order.product.description}", | |
} | |
end | |
end | |
order = Order.find(order_id) | |
charge_params = ChargeParams.new(order) | |
charge_customer = ChargeCustomer.new | |
charge_customer.charge!(**charge_params) | |
# ^^ | |
# || | |
# calls to_hash, then | |
# coerces to kwargs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment