Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

IO#set_encoding

(?::String | ::Encoding ext_or_ext_int_enc) -> self
(?::String | ::Encoding ext_or_ext_int_enc, ?::String | ::Encoding int_enc) -> self
set_encoding(ext_enc) → self
set_encoding(ext_enc, int_enc, **enc_opts) → self
set_encoding('ext_enc:int_enc', **enc_opts) → self

See Encodings.

Argument ext_enc, if given, must be an Encoding object or a String with the encoding name; it is assigned as the encoding for the stream.

Argument int_enc, if given, must be an Encoding object or a String with the encoding name; it is assigned as the encoding for the internal string.

Argument 'ext_enc:int_enc', if given, is a string containing two colon-separated encoding names; corresponding Encoding objects are assigned as the external and internal encodings for the stream.

If the external encoding of a string is binary/ASCII-8BIT, the internal encoding of the string is set to nil, since no transcoding is needed.

Optional keyword arguments enc_opts specify Encoding options.