    # File lib/rubygems/installer.rb, line 316
      def shebang(bin_file_name)
        if @env_shebang then
          "#!/usr/bin/env " + Gem::ConfigMap[:ruby_install_name]
        else
          path = File.join @gem_dir, @spec.bindir, bin_file_name

          File.open(path, "rb") do |file|
            first_line = file.gets
            if first_line =~ /^#!/ then
              # Preserve extra words on shebang line, like "-w".  Thanks RPA.
              shebang = first_line.sub(/\A\#!.*?ruby\S*/, "#!#{Gem.ruby}")
            else
              # Create a plain shebang line.
              shebang = "#!#{Gem.ruby}"
            end

            shebang.strip # Avoid nasty ^M issues.
          end
        end
      end