I'm trying to get the following code to work.
class Animal
end
class Tiger < Animal
@hunger = 100
def self.hunger
@hunger
end
def run
puts "The Tiger runs"
@hunger += 10
end
end
class Statistics
puts "This tigers hunger is: #{Tiger.hunger}"
end
tiger = Tiger.new()
tiger.run
So the tiger has a variable called hunger which is by itself at the top of the Tiger class. I want to make it so this variable can be changed throughout the class methods. For example in run the hunger is set to hunger += 10, but when I run this code I get an undefined method '+' for nil:NilClass (NoMethodError). What do I do to make this program work so the variable can be changed and then displayed in the Statistics class?