title: Ruby gem use configuration inside executable
body: <p>I am building a gem that needs a configuration when adding it to a project and also has an executable command.</p>
  <p>The structure that I have right now is:</p>
  <pre class="lang-rb prettyprint-override"><code>module MyGem
    class &lt;&lt; self
      attr_accessor :configuration
    end
  
    def self.configure
      self.configuration ||= Configuration.new
      yield(configuration)
    end
  
    class Configuration
      attr_accessor :base_url
  
      def initialize
        @base_url = ''
      end
    end
  
    def self.method_to_run
      puts self.configuration
    end
  end
  </code></pre>
  <p>Inside the <code>/bin/my-gem</code> file in the gem source, I have:</p>
  <pre class="lang-rb prettyprint-override"><code>#!/usr/bin/env ruby
  
  require 'my-gem'
  
  puts(&quot;config: #{MyGem.configuration}&quot;)
  puts MyGem.method_to_run
  </code></pre>
  <p>In this case the output when running <code>my-gem</code> is:</p>
  <pre><code>(empty line)
  config:
  </code></pre>
  <p>When I enter another project, with the initializer set, inside the <code>rails console</code>, the config is set and I can run everything smooth.</p>
  <p>How can I use the set configuration from a project even inside the command?</p>