Modules in Ruby are like classes with a few important differences. One of the differences is, a module cannot inherit from another module using the same syntax as class inheritance. However, its pretty easy to inherit a module's method into another module, by just using the include ModuleToInclude syntax. Here's an example if you are looking for one:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
module BaseModule | |
def cry | |
p "wa wa wa waaa" | |
end | |
end | |
module ExtendedModule | |
include BaseModule | |
#override the cry method from BaseModule | |
def cry | |
super | |
p "aa waa aa waa" | |
end | |
end | |
class MyClass | |
include ExtendedModule | |
end | |
MyClass.new.cry #=> wa wa wa waaa aa waa aa waa |