05-18-2018, 04:50 AM
(This post was last modified: 05-18-2018, 04:52 AM by DerVVulfman.)
C++ is modular, just as Ruby. Though not many code using the 'module' structure in Ruby (which is the largest of the structures in C++ and Ruby), we do use the Class structure (the second largest) and fill them with methods (or functions... your choice of names ).
Modules hold Classes. Classes hold methods (defs). Methods hold your individual routines... can also be called functions.
Some key method names are mirrored between C++ and Ruby. Both require the 'main' method which acts as the actual engine, running your code. And the initialize method is used for housekeeping, setting up values that are processed by your code.
Insofar as the initialize method within Ruby, it does exist for every class. Yep, even if you see one of the default classes like 'Scene_Battle' not having an initialize method, it does exist. And you can use the 'alias' method to prove it. The Alias method in Ruby allows you to rename a method (aka 'alias') to some other name allowing you to create a new method of the same name. This allows you to add code to a method. A cool little trick added into Ruby.
If the Scene_Battle class did not have an initialize method, this would not function. Just as C++ has initialize methods, Ruby does by default.
Modules hold Classes. Classes hold methods (defs). Methods hold your individual routines... can also be called functions.
Some key method names are mirrored between C++ and Ruby. Both require the 'main' method which acts as the actual engine, running your code. And the initialize method is used for housekeeping, setting up values that are processed by your code.
Insofar as the initialize method within Ruby, it does exist for every class. Yep, even if you see one of the default classes like 'Scene_Battle' not having an initialize method, it does exist. And you can use the 'alias' method to prove it. The Alias method in Ruby allows you to rename a method (aka 'alias') to some other name allowing you to create a new method of the same name. This allows you to add code to a method. A cool little trick added into Ruby.
Code:
#==============================================================================
# ** Scene_Battle (part 1)
#------------------------------------------------------------------------------
# This class performs battle screen processing.
#==============================================================================
class Scene_Battle
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
alias fred initialize
def initialize
fred
end
end
If the Scene_Battle class did not have an initialize method, this would not function. Just as C++ has initialize methods, Ruby does by default.