title: Variable available to class methods (within Concerns)
body: <p>I created a Rails Concern for my ActiveModel called <code>List</code></p>
  
  <p>When I run <code>Product.all</code> from the Rails Console, I get:</p>
  
  <blockquote>
    <p>NameError: undefined local variable or method `parameters' for
    Product:Class</p>
  </blockquote>
  
  <p>When parameters is changed to @parameters I get this error:</p>
  
  <blockquote>
    <p>NoMethodError: undefined method `include?' for nil:NilClass</p>
  </blockquote>
  
  <h1>Possible Solutions</h1>
  
  <p>Which is better, using a constant  PARAMETERS  or @@Parameters?  Pros and Cons?</p>
  
  <h1>Code</h1>
  
  <pre><code>module List
    extend ActiveSupport::Concern
  
    require 'csv'
  
      parameters =  [ 
                    :visible,
                    :desc,
                    :value,
                    ]
  
      attr_accessor(*parameters)
  
    def initialize(attributes = {})
      attributes.each do |name, value|
        send("#{name}=", value)
      end
    end
  
    def persisted?
      false
    end
  
    module ClassMethods 
      def all   
        list = []
        filename = File.join(Rails.root,"app/models/data/#{self.name.downcase}.csv")
        CSV.foreach(filename, headers: true) do |row|
          list &lt;&lt; self.new(row.select{|key,_| parameters.include? key.to_sym })
        end
        return list
      end
  
      def visible
        list = []
        filename = File.join(Rails.root,"app/models/data/#{self.name.downcase}.csv")
        CSV.foreach(filename, headers: true) do |row|
            list &lt;&lt; self.new(row.select{|key,_| parameters.include? key.to_sym })  if row['visible']=='1'
        end
        return list
      end
    end
  end
  </code></pre>