Skip to content

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

class method

Gem::AtomicFileWriter.byteslice_at_char_boundary

byteslice_at_char_boundary(string, max_bytesize)

Returns the longest prefix of string that is at most max_bytesize bytes and ends on a character boundary. A string that is invalid in its own encoding would be cut back to its last valid prefix, discarding an unbounded part of the name, so it is sliced as raw bytes instead and can still be cut mid-character.

See also .open