Can’t find what’s wrong with this.
def self.transfer(from, to, quantity)
transaction(from, to) do
from.withdraw(quantity)
to.deposit(quantity)
end
end
In the console this works
Stock.transaction do; sone.deposit(10); stwo.withdraw(10); end but if I do
Stock.transfer(sone, stwo, 10) I receive ArgumentError: wrong number of arguments (2 for 1)
Any idea?
The
transactionclass method takes a single (optional) options Hash as an argument but you’re passing itfromandto:You’re console test just uses
Stock.transactionwithout any arguments at all. Yourtransferclass method should probably look more like this: