Total newbie: Instance variables in ruby?

后端 未结 4 1345
旧巷少年郎
旧巷少年郎 2020-12-01 11:39

Pardon the total newbiew question but why is @game_score always nil?

#bowling.rb

class Bowling
  @game_score = 0
    def hit(pins)
        @game_score = @ga         


        
4条回答
  •  佛祖请我去吃肉
    2020-12-01 11:54

    @game_score will never get a value of zero here - you need to put it inside initialize, as in

    def initialize @game_score = 0 end

提交回复
热议问题