Created
October 18, 2019 05:14
-
-
Save rankitranjan/05130459ee4f36ce3d17549025adfe9e to your computer and use it in GitHub Desktop.
Add class methods and instance methods to class by including one 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 self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
def all | |
p 'all' | |
end | |
def find(id) | |
p "looking for entity with id=#{id}" | |
end | |
def a | |
p 'AClassMethods' | |
end | |
end | |
def a | |
p 'a' | |
end | |
end | |
class Aa | |
include A | |
end | |
o/p | |
Aa.a | |
=> AClassMethods | |
Aa.all | |
=> all | |
Aa.new.a | |
=> a | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment