Last active
January 10, 2021 22:08
-
-
Save dsasse07/c74d194d5e27487b4da1c87c8a37a694 to your computer and use it in GitHub Desktop.
Modules that are inherited can be passed along to a new parent Module
This file contains hidden or 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
module Module_A | |
def greeting_a | |
puts "Hello from Module A" | |
end | |
end | |
module Module_B | |
include Module_A | |
def greeting_b | |
puts "Hello from Module B" | |
end | |
end | |
class User | |
include Module_B | |
def greeting_c | |
puts "Hello from the instance method" | |
end | |
end | |
user = User.new | |
user.greeting_a #=> Hello from Module A | |
user.greeting_b #=> Hello from Module B | |
user.greeting_c #=> Hello from the instance method |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment