Thanks a lot for your help.
I have a Parent, a Child and a Module in two separate files. player_fabrizio is the Instance of the Player class, which is child of Settings. The instance player_fabrizio needs to use the @totalmoney variable of the instance new_settings.
require_relative "modules_test"
class Settings
include Variables
attr_reader :totalmoney
end
class Player < Settings
def initialize(kingdom, king)
@playerData = [kingdom, king]
end
def calculate
print @totalmoney
end
end
new_settings = Settings.new
new_settings.globalSettings(100, 2)
player_fabrizio = Player.new("MyDinasty", "Fabrizio")
player_fabrizio.calculate # no output
This is the file modules_test.rb. new_setting uses the method globalSettings of the module Variables to set the @totalmoney variable.
module Variables
def globalSettings(totalmoney, nplayer)
@totalmoney = totalmoney
return @totalmoney
end
end
The result of the method player_fabrizio.calculate should be 100, but instead no output is give.
I searched the forum, but I was not able to find a question. I read a question that had a similar issue, but I was not able to find an answer.
Thanks a lot for you help Fabrizio