title: Clone Class with class variables in Ruby
body: <p>I have some third <a href="https://github.com/ruby-i18n/i18n/blob/71a51b3243da7ca65885d2f81d91be15c92402a2/lib/i18n/config.rb" rel="nofollow noreferrer">party class</a>, which extensive uses class variables:</p>
  <pre><code>class Config
    def default_locale
      @@default_locale ||= :en
    end
  end
  </code></pre>
  <p>This class (I18n::Config) is quit large, and there are a lot of class variables. It is not a case to completely rewrite it.</p>
  <p>I need to get an instance of this class, which <strong>will not affect anyway</strong> original Config class variables.</p>
  <p>This is needed for Rails app, where I try to make I18n configurable <strong>per each request</strong> and <strong>thread safe</strong> at the same time.</p>
  <p>For thread safety I will use <a href="https://github.com/steveklabnik/request_store" rel="nofollow noreferrer">RequestStore</a>. I need to put there an independent Config instance, which will not affect original class variables.</p>