Skip to content

Instantly share code, notes, and snippets.

@LolWalid
Created September 25, 2019 12:03
Show Gist options
  • Save LolWalid/cb45a3d5bcc4274a7e69f51b3e29356d to your computer and use it in GitHub Desktop.
Save LolWalid/cb45a3d5bcc4274a7e69f51b3e29356d to your computer and use it in GitHub Desktop.
[Ruby] Class/Instance methods when using module
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