Another way for global variable in Ruby and Sinatra
<p>I am using Ruby and Sinatra for my application. </p>

<p>I want to assign a variable which will be used in different classes and methods. </p>

<p>In my app file ie 'Millennium' is my app name so the application file is <code>millennium.rb</code> contains :</p>

<pre><code>require 'rubygems'
require 'sinatra'
require 'yaml'
require 'active_record'
require 'sidekiq'
require 'statsd'

custom_statsd = Statsd.new('localhost', 8125)  #custom_statsd available across the application. 

class Millennium &lt; Sinatra::Application
  set :use_queueing_in_dev, false # useful for debugging queue issues.
  set :protection, :except =&gt; [:json_csrf]

  configure do
    # These allow our error handlers to capture the errors
    disable :raise_errors
    disable :show_exceptions
    enable :logging
  end

  before do
    #logger.info request.body.read
    request.body.rewind
  end
end
</code></pre>

<p>Here I want to use value of <code>custom_statsd</code> variable in any class of my application. </p>

<p>I think using "$" is not a good idea. Please suggest me what is the other way to do this.</p>

<p>Thanks!!!!</p>