module Rails

def self.gem_version

Returns the version of the currently loaded Rails as a Gem::Version
def self.gem_version
  Gem::Version.new VERSION::STRING
end

def self.version

Returns the version of the currently loaded Rails as a string.
def self.version
  VERSION::STRING
end

def application

def application
  @application ||= (app_class.instance if app_class)
end

def backtrace_cleaner

def backtrace_cleaner
  @backtrace_cleaner ||= begin
    # Relies on Active Support, so we have to lazy load to postpone definition until AS has been loaded
    require 'rails/backtrace_cleaner'
    Rails::BacktraceCleaner.new
  end
end

def configuration

The Configuration instance used to configure the Rails environment
def configuration
  application.config
end

def env

Rails.env.production? # => false
Rails.env.development? # => true
Rails.env # => "development"

Returns the current Rails environment.
def env
  @_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development")
end

def env=(environment)

Rails.env = "staging" # => "staging"

Sets the Rails environment.
def env=(environment)
  @_env = ActiveSupport::StringInquirer.new(environment)
end

def groups(*groups)

# => [:default, :production] for Rails.env == "production"
# => [:default, :development, :assets] for Rails.env == "development"
# Returns

groups assets: [:development, :test]

* The optional envs given as argument and the hash with group dependencies;
* The environment variable RAILS_GROUPS;
* The Rails environment;

Returns all rails groups for loading based on:
def groups(*groups)
  hash = groups.extract_options!
  env = Rails.env
  groups.unshift(:default, env)
  groups.concat ENV["RAILS_GROUPS"].to_s.split(",")
  groups.concat hash.map { |k, v| k if v.map(&:to_s).include?(env) }
  groups.compact!
  groups.uniq!
  groups
end

def public_path

# => #
Rails.public_path

rails project, otherwise it returns nil if there is no project:
Returns a Pathname object of the public folder of the current
def public_path
  application && Pathname.new(application.paths["public"].first)
end

def root

# => #
Rails.root

otherwise it returns nil if there is no project:
Returns a Pathname object of the current rails project,
def root
  application && application.config.root
end