Skip to content

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

instance method

StringIO#external_encoding

() -> ::Encoding
external_encoding → encoding or nil

Returns an Encoding object that represents the encoding of the string; see Encodings:

Example
strio = StringIO.new('foo')
strio.external_encoding # => #<Encoding:UTF-8>

Returns nil if self has no string and is in write mode:

Example
strio = StringIO.new(nil, 'w+')
strio.external_encoding # => nil
See also #eof? #fcntl #eof #fileno also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0