To read a file that uses the UTF-8 encoding scheme:
File.new("main.rb", "r:utf-8").each { |line| puts line }
Here, we're reading a file in the UTF-8 encoding.
To determine the external encoding of an I/O object using its external_encoding method:
puts File.open("main.rb", "r:utf-8").external_encoding puts File.open("main.rb", "r").external_encoding
If your default encoding is not US-ASCII, the second line will return whatever your default encoding actually is.