You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
IO::EncodingOptions is a weird type. It is marked as public, but is essentially a record with 2 fields that are used exclusively by the private types IO::Encoder and IO::Decoder, wrappers around the iconv interface. There are no public interfaces that produce or consume IO::EncodingOptions values at all.
That type's #invalid field is even weirder (this time the same goes for public methods like String#encode and File.tempfile). It is a Symbol? and the only acceptable values are nil and :skip. This sounds like an opportunity to introduce an enum:
enumString::InvalidAction# alternatively `String::InvalidByteSequenceAction`Raise# an exception is raised on invalid byte sequencesSkip# invalid byte sequences are ignored# :nodoc:defself.from_invalid(invalid)
if invalid.nil?
Raiseelsif invalid ==:skipSkipelseraiseArgumentError.new "Valid values for `invalid` option are `nil` and `:skip`, not #{invalid.inspect}"endendend
The overloads that take a Symbol? should be deprecated in favor of this enum:
classStringdefencode(encoding : String, invalid : String::InvalidAction=:raise) : Bytes; ...; end
@[Deprecated]
defencode(encoding : String, invalid : Nil) : Bytes
encode(encoding, String::InvalidAction.from_invalid(invalid))
end# How to we deprecate `Symbol?` and restriction-less overloads properly?# (they will be matched for `invalid: :skip`, but we still want to support autocasting here)end
IO::EncodingOptions can be deprecated too, and IO::Encoder / IO::Decoder should use an equivalent internal type, unless there is a reason to support this struct in the public interface of encoding-related methods.
The text was updated successfully, but these errors were encountered:
IO::EncodingOptions
is a weird type. It is marked as public, but is essentially arecord
with 2 fields that are used exclusively by the private typesIO::Encoder
andIO::Decoder
, wrappers around the iconv interface. There are no public interfaces that produce or consumeIO::EncodingOptions
values at all.That type's
#invalid
field is even weirder (this time the same goes for public methods likeString#encode
andFile.tempfile
). It is aSymbol?
and the only acceptable values arenil
and:skip
. This sounds like an opportunity to introduce an enum:The overloads that take a
Symbol?
should be deprecated in favor of this enum:IO::EncodingOptions
can be deprecated too, andIO::Encoder
/IO::Decoder
should use an equivalent internal type, unless there is a reason to support this struct in the public interface of encoding-related methods.The text was updated successfully, but these errors were encountered: