Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

module

khmp

Sponsor

module is the superclass/parent to class. Remember that in Ruby almost everything is an object. Not sure enough to say everything. Anyway you can treat them just as you would classes. But in front of method names you would place "self." or "Module_Name" where module name was, well the name of the module. For example:

Code:
module Toaster
  def self.toast(bread)
    return bread.toasted
  end
end

Please check here as well: http://www.ruby-doc.org/docs/ProgrammingRuby/  Look up Module.

Good luck with it Lorem Ipsum! :thumb:
 
Modules are great for naming conventions. Like, if khmp, SephirothSpawn, and I are all making scripts that you use, and we all use constants that have similar names, and there is a risk of overlapping, we can hold our constants in Modules.

like, for example:
Code:
module Prexus
  LOLCHEESE = 'HAH'
end
module khmp
  LOLCHEESE = 'ROFL'
end

khmp::LOLCHEESE     #=> 'ROFL'
Prexus::LOLCHEESE     #=> 'HAH'
 

e

Sponsor

Basically, modules are abstract classes; in other words, they are EXACTLY the same as classes, except that you can NEVER use the new method on them; thus you do not need to define a initialize method.

Furthermore, with modules, you can have multiple inheritance (in the forms of Mix-Ins). Basically, when you create a new class, and you want it to be a subclass ( a children of, say, Window ), you'd do :

Code:
class Window_MyWindow < Window

end

Unfortunately, you CANNOT do something like :

Code:
class Window_MyWindow < Window < OtherWindow

end

You can only extend from one class. A way to circumvent that is to use a module.

Code:
module OtherWindow
# Methods
end

class Window_MyWindow < Window
include OtherWindow

end

Read Ruby's Pragmatic book. It's available for free. And if you feel adventurous, read Why's (poignant) Guide to Ruby.
 

khmp

Sponsor

etheon":35fk4usy said:
Basically, modules are abstract classes; in other words, they are EXACTLY the same as classes, except that you can NEVER use the new method on them; thus you do not need to define a initialize method.

My apology there is no initialize so I will correct my original post. Thanks etheon for bringing that to my attention.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top