Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

IO#set_encoding

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; it is assigned as the encoding for the stream.

Argument int_enc, if given, must be an Encoding object; 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.

Optional keyword arguments enc_opts specify Encoding options.

See also #seek #set_encoding_by_bom #scroll_forward #stat also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0