我创建了一个如下所示的模型:
class Stock < ActiveRecord::Base
attr_accessible :company, :stock_ticker, :current_stock_price, :free_cash_flow, :num_shares, :PE_ratio, :dividend_per_share, :dividend_growth_rate, :beta, :cost_of_equity, :rate_of_return, :fcf_share_value, :capm_share_value, :dividend_share_value, :composite_share_value
def initialize(submitted_stock)
@company = submitted_stock
@stock_ticker = submitted_stock
@current_stock_price = 0
@free_cash_flow = 0
@num_shares = 0
@PE_ratio = 0
@dividend_per_share = 0
@dividend_growth_rate = 0
@beta = 0
@cost_of_equity = 0
@rate_of_return = 0
@fcf_share_value = 0
@capm_share_value = 0
@dividend_share_value = 0
@composite_share_value = 0
end
end
当我尝试创建一个新的Stock
:
s = Stock.new("MSFT")
没有创建新库存,而是得到以下响应:
#<Stock not initialized>
我使用 Pry 并看到它正在将值分配给实例变量,但它没有初始化对象或创建它。