Created
November 30, 2011 10:58
-
-
Save pda/1408675 to your computer and use it in GitHub Desktop.
Example of class @instance_var that used to be a @@class_var
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 Category::Categorizable | |
extend ActiveSupport::Concern | |
included do | |
def self.categorizable_through(table) | |
has_many table, dependent: :destroy | |
@categorizable_join_model = Kernel.const_get(table.to_s.singularize.classify) | |
end | |
def categories | |
Category::CategoriesRelation.new( | |
self, | |
self.class.instance_variable_get(:@categorizable_join_model) | |
) | |
end | |
end | |
end |
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 Category::Categorizable | |
extend ActiveSupport::Concern | |
included do | |
def self.categorizable_through(table) | |
@@categorizable_join_model = Kernel.const_get(table.to_s.singularize.classify) | |
end | |
def categories | |
Category::CategoriesRelation.new(self, @@categorizable_join_model) | |
end | |
end | |
end |
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
class Post < ActiveRecord::Base | |
include Category::Categorizable | |
categorizable_through :categories_posts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment