Classes vs. Modules

8.15.15


The first main difference to note about classes and modules is what they are all about. Classes are all about objects and you have the ability to create as many as you desire. You can almost imagine a class as a "mini-module". Modules are all about functions but you can only create one, which is one of the biggest differences. You can "create" a class but cannot do that with a module Another difference is that of its syntax and how to properly call a class or module. Here is a simple table of the difference between the two forms...


In conclusion, by the chart you can easily see that a class and module are made of the same structure. The only differences are the ones that make up the structure it self. They are both made up of methods and constants but hold different types of methods. The main reason to learn the difference is that you can use them properly. Modules would be very good for something in need of authentication or something involving a mixin facility. Classes however can be used mainly for object creation, the one large thing modules cannot do.

blogs