Created
December 12, 2012 10:01
-
-
Save swarut/4266531 to your computer and use it in GitHub Desktop.
Ruby : Example of defining class and instance methods in module #ruby #module #class_method #instance_method #mixin
This file contains 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 NetworkBelongable | |
module OneToOne | |
extend ActiveSupport::Concern | |
included do | |
self.has_many "#{self.to_s.downcase}_networks".to_sym | |
self.has_many :networks, through: "#{self.to_s.downcase}_networks".to_sym | |
Network.has_many "#{self.to_s.downcase}_networks".to_sym | |
Network.has_many self.to_s.downcase.pluralize.to_sym, through: "#{self.to_s.downcase}_networks".to_sym | |
end | |
module ClassMethods | |
#class method of the mixined model | |
def hi | |
puts "hi" | |
end | |
end | |
#instance method of the mixined model | |
def hihi | |
puts "hi" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment