Skip to content

Instantly share code, notes, and snippets.

@rankitranjan
Created October 18, 2019 05:14
Show Gist options
  • Save rankitranjan/05130459ee4f36ce3d17549025adfe9e to your computer and use it in GitHub Desktop.
Save rankitranjan/05130459ee4f36ce3d17549025adfe9e to your computer and use it in GitHub Desktop.
Add class methods and instance methods to class by including one Module
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