title: How does Rails.application.configure block works without providing a variable name
body: <p>In Rails, it's common to see a pattern like this (in <code>config/environments/development.rb</code> for example):</p>
  
  <pre><code>Rails.application.configure do
  
    config.some_option = some_value
  
  end
  </code></pre>
  
  <p>I was intrigued by this idiom since I was recently researching how these configure <code>blocks</code> work and ended up discovering <a href="https://robots.thoughtbot.com/mygem-configure-block" rel="nofollow noreferrer">this very similar pattern</a>, where the <code>configure</code> method initializes an (generally memoized) instance of a configuration Class (that has the accessors for the configuration options) and yield that instance object to the block. Something like this: </p>
  
  <pre><code>module Clearance
    class &lt;&lt; self
      attr_accessor :configuration
    end
  
    def self.configure
      self.configuration ||= Configuration.new
      yield(configuration)
    end
  
    class Configuration
      attr_accessor :mailer_sender
  
      def initialize
        @mailer_sender = 'donotreply@example.com'
      end
    end
  end
  </code></pre>
  
  <p>That's why <code>Clearance.configure {|config| config.mailer_sender = 'something'}</code> works, because it's yielding that instance of Configuration class to the block variable <code>config</code>. </p>
  
  <p>But the way Rails does it, there's no variable being passed to that block. There's no <code>Rails.application.configure do |config|</code> so the block can change the configuration object accessors. I thought <code>config</code> would be undefined inside that block, but it isn't. </p>
  
  <p>Tried looking at rails source code and I suspect it has to do with the <a href="https://github.com/rails/rails/blob/5ccdd0bb6d1262a670645ddf3a9e334be4545dac/railties/lib/rails/railtie/configurable.rb" rel="nofollow noreferrer">configurable module</a>, but I couldn't 100% understand the code I found there. </p>