Reputation: 599
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?
Upvotes: 0
Views: 77
Reputation: 434585
The transaction
class method takes a single (optional) options Hash as an argument but you're passing it from
and to
:
transaction(from, to) do
You're console test just uses Stock.transaction
without any arguments at all. Your transfer
class method should probably look more like this:
def self.transfer(from, to, quantity)
transaction do
from.withdraw(quantity)
to.deposit(quantity)
end
end
Upvotes: 1