Created
September 25, 2019 12:03
-
-
Save LolWalid/cb45a3d5bcc4274a7e69f51b3e29356d to your computer and use it in GitHub Desktop.
[Ruby] Class/Instance methods when using 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 A | |
def method_a | |
puts 'instance method A' | |
end | |
class_methods do | |
def method_a | |
puts 'class method A' | |
end | |
end | |
end | |
class B | |
include A | |
end | |
class C | |
extend A | |
end | |
B.method_a # "instance method A" | |
B.new.method_a # "class method A" | |
C.method_a # "instance method A" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment