1.

What is a module?

Answer»

A module in ruby has multiple method implementations, various constants, and different class variables. Modules are DEFINED similarly to a class with a module keyword.

  • Inheritance is not SUPPORTED by modules
  • Cannot create a subclass of a module.
  • Modules cannot be instantiated.
  • Modules are used as namespaces and as mixins.
  • A class can be a module, but a module can never be a class.
  • A class cannot USE mixins like modules.
  • Module name must start with a CAPITAL letter.

Syntax:

module Module_name  # statements to be executed end For example: # Creating a module with name Hello module Hello # PREFIX with the name of the Module # module method   def Hello.welcome    puts “Hello!! Welcome” End end # calling the methods of the module Puts Hello.welcome Hello!! Welcome


Discussion

No Comment Found