Mixins and Modules in separate files


#1

Hello Everybody,

I will try to make the question as simple as possible, I am developing a game with Ruby and I don't understand very well how to program with Ruby Object Oriented.
The class Player will be instantiated for every player, some data from settings will be shared with Player to make calculations, also I have a Module that manages all the messages in another file of the same folder so i use require_relative. I do not know if I should instantied the Setting and doing them with a Class or just do them with a Module, hardcode the settings and use the variables available in the Player class by extending the Module to the Player class.

So the main question is, from the code below, how does the Player Class use the data from the Settings class, as i need to instantiate setting when I ask to n of player and the quantity of money at the start of the game, then how can variable be available between classes, also when there is no inheritance. Global Variable are available everywhere right? but, they should not be used so I am avoiding that.
Also I have done some research on mixins, modules, inheritance and global/local/class variables, but maybe I should watch some additional training videos to get this fondaments, do you have any advice?

Can the instance of Setting call a method in a Module written in another file (require_relative "modules"), this method could save and store the variable total money and then doing mixins, set the include in the class Player, so that the instance player_fabrizio can call calculate and calculate would use the variable @totalmoney from the module?
The question is i know how to call the method in the module from another file with require_relative, but i was never
able to get in return from the method of the module in the other file a variable. Is it enough using require_relative in the first file to call a method of a module in the second file and get in return a total_money variable?

Thanks a lot for your help

any advice will help me figuring how Ruby OO works

Best Regards
Fabrizio

class MainData
      def initialize(kingdom, king)
            @playerData = [kingdom, king]
      end
end

class Settings 
    def globalSettings(totalmoney, nplayer)
          @totalmoney = variable
          @nplayer = nplayer
    end
end

class Player < MainData
   def calculate
         @playermoney = @totalmoney / @nplayer
   end
end

player_fabrizio = MainData.new("MyDinasty", "Fabrizio")

new_settings = Settings.new
new_settings.globalSettings(100, 2)

fabrizio_money = Player.new
fabrizio_money.calculate

#2

I posted the question on Stackoverflow and I received the following answer

Thanks a lot
Fabrizio