ADVERTISEMENT
ADVERTISEMENT

Ruby program to demonstrate a simple module

Ruby Example: Write a program to demonstrate a simple module.
Submitted by Nidhi, on December 29, 2021

Problem Solution:

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.

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 Method1, Method2, and Method3 inside the created module. After that, we called all defined methods and printed appropriate messages.

Ruby Modules and Mixins Programs »


ADVERTISEMENT


ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.