I am trying to figure out how to pass variables between classes in Ruby. The example I am working on now is a game, where the players health, equipment, etc keeps changing and is passed from scene to scene until the game is over. Here is what I have so far:
class Player
def enter()
end
end
class MyPlayer < Player
def initialize()
dog_biscuits = false
end
end
class Scene
def enter()
end
end
class Entrance < Scene
def enter(player)
puts "You are in the entrance"
if player.dog_biscuits == false
puts "You don't have any biscuits."
end
end
end
player = MyPlayer.new
entrance = Entrance.new
entrance.enter(player)
Whenever I run this, I get the following error message:
entrance.rb:20:in `enter': undefined method `dog_biscuits' for #<MyPlayer:0x007fbfe2167f20> (NoMethodError)
I am running ruby 2.2.3p173 on OSX El Capitan.