Why is force_encoding ("BINARY") used here?

When we install Rails, we get this rails"executable":

#!/usr/bin/env ruby
#
# This file was generated by RubyGems.
#
# The application 'railties' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'rubygems'

version = ">= 0"

if ARGV.first
  str = ARGV.first
  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
  if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
    version = $1
    ARGV.shift
  end
end

gem 'railties', version
load Gem.bin_path('railties', 'rails', version)

I wonder what it means to do force_encoding("BINARY")on this Line. What are the possible values ​​for what is force_encodingneeded? I would have thought that people would only indicate versions using numbers and letters here.

+4
source share
1 answer

This is not a special thing with rails - it is rubigem wrappers for each ruby ​​executable file in stone. The call force_encodingwas added in 6bf71914

, - , , , , . , , , ruby.

issue , .

+2

Source: https://habr.com/ru/post/1583917/


All Articles