Skip to content

Instantly share code, notes, and snippets.

@dsasse07
Last active January 10, 2021 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsasse07/c74d194d5e27487b4da1c87c8a37a694 to your computer and use it in GitHub Desktop.
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
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