0

Let me write down some difference between them as I know

  1. Modules can't be instantiated, whereas classes can be
  2. Multiple modules can be included / extended, whereas only one class can be inherited

Aside from the above mentioned two, I don't see any other differences between them

  1. Both can have class level variables (@@)
  2. Both can have class-instance level variables (@, initialized directly in the module/class)
  3. Both can have instance variables (@, initialized inside the methods)
  4. Both can have global variables ($)
  5. Both can have methods that can be directly called using their names (prefixed with "self")
  6. Both can have inner classes
  7. A class that includes and extends a module has access to all its methods (non-private) which is the same as inheriting from a class does for the subclass

Leaving the multiple inheritance out, is the only difference between classes and modules are that of creating objects?

(I don't have a lot of experience in Ruby, just trying to get my head around the difference between classes and modules. Please feel free to point out anything that I might have missed)

x-treme
  • 1,606
  • 2
  • 21
  • 39

0 Answers0