Does anyone have any ideas on how I can refactor these methods to get rid of the duplication? The first, third and fourth lines of both methods do the same thing. I'm having trouble for some reason because the second argument of both methods are of different types (or rather they represent different types of values).
I was think of using procs and having the different code be a block, but I couldn't find a solution.
def buy_in_cash(symbol, cash_amt) # second argument is cash
market_price = @exchange.price_by_symbol(symbol)
coin_amt = cash_to_coin(cash_amt, market_price) # different
withdraw_cash(cash_amt)
@transactions << Transaction.new(symbol, coin_amt, market_price)
end
def buy_in_coin(symbol, coin_amt) # here second argument is coin
market_price = @exchange.price_by_symbol(symbol)
cash_amt = coin_to_cash(coin_amt, market_price) # different
withdraw_cash(cash_amt)
@transactions << Transaction.new(symbol, coin_amt, market_price)
end