我正在关注ruby.railstutorial.我运行命令"git push heroku master",它会吐出这个错误.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Run Code Online (Sandbox Code Playgroud)
我在我的rails app"/ Users/lexi87/rails_projects/first_app"里面.有解决方案吗
我有以下代码:
class BookPrice
attr_accessor :price
def initialize(price)
@price = price
end
def price_in_cents
Integer(price*100 + 0.5)
end
end
b = BookPrice.new(2.20)
puts b.price_in_cents
Run Code Online (Sandbox Code Playgroud)
这一切都很好,产生220.但当我更换第二行attr_accessor:价格与:
def price
@price = price
end
Run Code Online (Sandbox Code Playgroud)
我得到堆栈级别太深(SystemStackError)错误.这是怎么回事?我知道我可以用@price替换Integer(价格*100 + 0.5)而不是方法调用价格,但是我想保持它与OOP原因的方式.如何在没有attr_accessor的情况下使这段代码按原样运行?