Consider a hash which can be accessed and updated anywhere in a rails application without a database
<p>An application which performs CRUD operations without the database accessing data via csv file .I wanna store the data from csv file into the hash . I have considered this method but end up errors . </p>

<pre><code>  employee.rb    
    class Employee
    include ActiveModel::Serializers::JSON
   include ActiveModel::Validations
 include ActiveModel::Model
 include ActiveModel::Dirty

  attr_accessor  :id, :name , :email , :number , :salary 

  define_attribute_methods  :id, :name , :email , :number , :salary
   validates :name, presence: true,  length: { maximum: 100 }

 def attributes
  {'id' =&gt; nil , 'name' =&gt; nil , 'email' =&gt; nil , 'number' =&gt; nil ,     'salary' =&gt; nil }
   end

   def self.find(id)
   p ' fof fof fof fof o'
   p @employees
   raw = Parse.get("employee", id.to_s)

   employee = Employee.new
   employee.id = raw["id"]
   employee.name = raw["name"]
   employee.email = raw["email"] 
   employee.number = raw["number"] 
   employee.salary = raw["salary"] 

 #  etc for the others

 p  employee # Return the newly-created instance
      end

   def capitalized_name
    name.capitalize
end

  def self.all
     ObjectSpace.each_object(self).to_a
   end
  end
</code></pre>

<p>employee_controller.rb </p>

<pre><code>   class EmployeesController &lt; ApplicationController

   require 'csv'



def index

CSV.foreach('data.csv') do |row|
    #Employee.create!(row.to_hash)
    a = []
    a = row.inspect 
    p a 
    a = a.gsub(/(\[\"|\"\])/, '').split('", "')
    p a 
     e = Employee.new 
     e.id = a[0]
     e.name = a[1]
     e.email = a[2]
     e.number = a[3]
     e.salary = a[4]
    #m  = e.serializable_hash
   # m = m.keys.zip(a).to_h
    employee_values = e.instance_values 
    all = Data.instance
    all.add("e.i = employee_values" )
end
@employees = ::Employee.all
p @employees
p "blah blah blah"
p all.keys 
end

 def new
   @employee = Employee.new
 end

 def edit
     @employee = Employee.find(params[:id])
 end 

 def create
     @employee = Employee.new(employee_params)

respond_to do |format|
  if @employee.save
    format.html { redirect_to @employee, notice: 'Employee was successfully created.' }
    format.json { render :show, status: :created, location: @employee }
  else
    format.html { render :new }
    format.json { render json: @employee.errors, status: :unprocessable_entity }
  end
  end
 end

 def destroy
   @employee.destroy
    respond_to do |format|
      format.html { redirect_to employees_url, notice: 'Employee was successfully destroyed.' }
     format.json { head :no_content }
    end
   end

  private
   # Use callbacks to share common setup or constraints between actions.
   def set_employee
     @employee = Employee.find(params[:id])
   end

  # Never trust parameters from the scary internet, only allow the white list through.
def employee_params
  params.require(:employee).permit(:id ,:name, :hiredate, :salary)
end
</code></pre>

<p>end</p>

<p>Then created a subclass for Hash to be accessed anywhere and saved it in initializers as creatting a global variable is bad practice 
         require 'singleton'</p>

<pre><code>class Data &lt; Hash
  include Singleton

  def initialize
   super([])
 end

 def add src
   src.to_s.split(";").each do |item|
    splitted = item.split("=")
    self[splitted[0]] = splitted[1]
  end
end
</code></pre>

<p>end</p>