title: How to access a class method (or variable) in an instance method using concern?
body: <p>I need to access a class method (defined in ClassMethods) in an instance method inside a concern.</p>
  
  <p>My brain is melted and I'm sure that is a simple thing that I'm doing wrong.</p>
  
  <p>I need to access <code>comparable_opts</code> inside <code>comparison</code>. How can I do it?</p>
  
  <p>Follow snippets below:</p>
  
  <p>Concern</p>
  
  <pre><code># app/models/concerns/compare.rb
  module Compare
    extend ActiveSupport::Concern
  
    attr_accessor :comparable_opts 
  
    module ClassMethods
      attr_reader :arguable_opts
  
      def comparable_opts
        @@comparable_opts
      end
  
      private
        def default_opts
          @default_opts ||= {fields: [:answers_count, 
                                        :answers_correct_count, 
                                        :answers_correct_rate, 
                                        :users_count]}
        end
  
        def compare(opts={})
          @comparable_opts = default_opts.merge(opts)
        end
    end
  
    def comparison
    end
  end
  </code></pre>
  
  <p>Model</p>
  
  <pre><code># app/models/mock_alternative.rb
  class MockAlternative &lt; ActiveRecord::Base
    include Compare
  
    belongs_to :mock, primary_key: :mock_id, foreign_key: :mock_id
  
    compare fields: [:answers_count, :question_answers_count, :question_answers_rate],
            with: :mock_aternative_school
  
    def question_answers_rate
      self[:answers_count].to_f/self[:question_answers_count].to_f
    end
  end
  </code></pre>