# File src/ruby_supportlib/phusion_passenger/platform_info/ruby.rb, line 258
    def self.rvm_ruby_string
      if in_rvm?
        # RVM used to export the necessary information through
        # environment variables, but doesn't always do that anymore
        # in the latest versions in order to fight env var pollution.
        # Scanning $LOAD_PATH seems to be the only way to obtain
        # the information.

        # Getting the RVM name of the Ruby interpreter ("ruby-1.9.2")
        # isn't so hard, we can extract it from the #ruby_executable
        # string. Getting the gemset name is a bit harder, so let's
        # try various strategies...

        # $GEM_HOME usually contains the gem set name.
        # It may be something like:
        #   /Users/hongli/.rvm/gems/ruby-1.9.3-p392
        # But also:
        #   /home/bitnami/.rvm/gems/ruby-1.9.3-p385-perf@njist325/ruby/1.9.1
        if GEM_HOME && GEM_HOME =~ %r{rvm/gems/(.+)}
          return $1.sub(/\/.*/, '')
        end

        # User might have explicitly set GEM_HOME to a custom directory,
        # or might have nuked $GEM_HOME. Extract info from $GEM_PATH.
        if GEM_PATH
          GEM_PATH.split(':').each do |gem_path|
            if gem_path =~ %r{rvm/gems/(.+)}
              return $1.sub(/\/.*/, '')
            end
          end
        end

        # That failed too. Try extracting info from from $LOAD_PATH.
        matching_path = $LOAD_PATH.find_all do |item|
          item.include?("rvm/gems/")
        end
        if matching_path && !matching_path.empty?
          subpath = matching_path.to_s.gsub(/^.*rvm\/gems\//, '')
          result = subpath.split('/').first
          return result if result
        end

        # On Ruby 1.9, $LOAD_PATH does not contain any gem paths until
        # at least one gem has been required so the above can fail.
        # We're out of options now, we can't detect the gem set.
        # Raise an exception so that the user knows what's going on
        # instead of having things fail in obscure ways later.
        STDERR.puts "Unable to autodetect the currently active RVM gem " +
          "set name. This could happen if you ran this program using 'sudo' " +
          "instead of 'rvmsudo'. When using RVM, you're always supposed to " +
          "use 'rvmsudo' instead of 'sudo!'.\n\n" +
          "Please try rerunning this program using 'rvmsudo'. If that " +
          "doesn't help, please contact this program's author for support."
        exit 1
      end
      return nil
    end