Ruby, stack level too deep (SystemStackError)

前端 未结 4 1884
时光取名叫无心
时光取名叫无心 2021-02-18 15:40

I have the following code:

class BookPrice
  attr_accessor :price
  def initialize(price)
    @price = price
  end

  def price_in_cents
    Integer(price*100 +          


        
4条回答
  •  Happy的楠姐
    2021-02-18 16:15

    You need to do:

    @price = self.price
    

    to differentiate between your object attribute price and your method parameter price.

提交回复
热议问题