Skip to content

Documentation


Documentation / @blazetrails/activesupport / chomp

Function: chomp() ​

chomp<T>(str, separator?): T

Defined in: packages/ruby-compat/dist/string/chomp.d.ts:14

With no separator (or undefined), removes a single trailing \n, \r\n, or \r. With a separator string, removes that suffix if present. An empty-string separator (Ruby paragraph mode) strips every trailing \n, each with the \r before it (vendor/ruby/v3.3.11/string.c:9682). A "\n" separator is the smart newline case, not a literal suffix strip: chompped_length (vendor/ruby/v3.3.11/string.c:9700-9730) removes a trailing "\r\n", "\n" or a lone "\r", so chomp(str, "\n") is the same operation as chomp(str). A Uint8Array is an ASCII-8BIT String, chomped by the smart-newline rule over its bytes (no other separator is ported for bytes).

Type Parameters ​

Type Parameter
T extends string | Uint8Array<ArrayBufferLike>

Parameters ​

ParameterType
strT
separator?string

Returns ​

T

No Rails Equivalent ​

PERMANENT — Ruby core String#chomp (vendor/ruby/v3.3.11/string.c:9786), which Rails inherits rather than defines.