Skip to content

Instantly share code, notes, and snippets.

@swarut
Created December 12, 2012 10:01
Show Gist options
  • Save swarut/4266531 to your computer and use it in GitHub Desktop.
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
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