Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

ruby
file
encoding
communitycreator

What is the external_encoding property of a file in Ruby?

okwudili onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

Overview

The external_encoding property of a file returns the Encoding object that represents the file's encoding. The Encoding object contains all the encodings available in Ruby.

Syntax

file.external_encoding
Syntax of the external_encoding property

Return value

This property returns the encoding of the file.

Example

Let's look at the example below:

main.rb
test.txt
# create new file
f = File.new("test.txt")
# print encoding of file
puts f.external_encoding
An example of the external_encoding property

Explanation

  • Line 2: We create a new file, test.txt.
  • Line 5: We print the encoding of the file to the console.

RELATED TAGS

ruby
file
encoding
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring