Q:

Ruby program to demonstrate a simple module

belongs to collection: Ruby Modules and Mixins Programs

0

In this program, we will create a module and define some methods inside the method. Then we will call all methods defined inside the method.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to demonstrate a simple module is given below. The given program is compiled and executed successfully.

# Ruby program to demonstrate 
# a simple module

module MyModule
    def MyModule.Method1
        puts "Inside Method1";
    end
    
    def MyModule.Method2
        puts "Inside Method2";
    end
    
    def MyModule.Method3
        puts "Inside Method3";
    end
end

MyModule.Method1();
MyModule.Method2();
MyModule.Method3();

Output:

Inside Method1
Inside Method2
Inside Method3

Explanation:

In the above program, we created a module MyModule. Then we defined 3 methods Method1Method2, and Method3 inside the created module. After that, we called all defined methods and printed appropriate messages.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Ruby program to create a module with variables... >>