Sha256: 5b5aad3e2a7875f185e1f3a5cf68402b0822f7d84698ea360cd4ec62fc9b8ac1
Contents?: true
Size: 647 Bytes
Versions: 2
Compression:
Stored size: 647 Bytes
Contents
require 'observer' class Account include Observable attr_reader :id, :stock, :cash, :name attr_accessor :ai def initialize id, name, stock, cash @id, @name, @stock, @cash = id, name, stock, cash @ai = false end def update_name name if @name != name @name = name changed notify_observers end end def on_trade order, amount if order.side == :buy @stock += amount @cash -= order.price * amount else @stock -= amount @cash += order.price * amount end end def net_value current_price @cash + @stock * current_price end def ai? @ai end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ruby-trade-0.2 | server/account.rb |
ruby-trade-0.1 | server/account.rb |