windows上的ruby:如何在环境变量中存储重音字符串并将其保持原样

时间:2015-09-26 04:05:30

标签: ruby mingw32

当我将包含é的字符串保存到ENV变量中时,然后 把它放回红宝石中,似乎搞砸了。我做错了吗?

要演示,此脚本

require 'zlib'
puts "Encoding.default_external is #{Encoding.default_external}"
puts "Encoding.default_internal is #{Encoding.default_internal}"
puts "File.expand_path("") is #{File.expand_path("")}"
puts "File.expand_path("") size is #{File.expand_path("").size}"
puts "File.expand_path("").encoding is #{File.expand_path("").encoding}"
puts "File.expand_path("") checksum is #{Zlib::crc32(File.expand_path(""))}"
puts "Saving"
ENV['ABC'] = File.expand_path("")
puts "ENV['ABC'] is #{ENV['ABC']}"
puts "ENV['ABC'] size is #{ENV['ABC'].size}"
puts "ENV['ABC'].encoding is #{ENV['ABC'].encoding}"
puts "ENV['ABC'] checksum is #{Zlib::crc32(ENV['ABC'])}"

产生

C:\Users\Name\Nestlé\learn-rails>ruby test.rb
Encoding.default_external is IBM437
Encoding.default_internal is
File.expand_path() is C:/Users/Name/Nestlé/learn-rails
File.expand_path() size is 32
File.expand_path().encoding is UTF-8
File.expand_path() checksum is 1553489379
Saving
ENV['ABC'] is C:/Users/Name/NestlAc/learn-rails
ENV['ABC'] size is 35
ENV['ABC'].encoding is ASCII-8BIT
ENV['ABC'] checksum is 3711979874
C:\Users\Name\Nestlé\learn-rails>

0 个答案:

没有答案