Issue #21552 has been updated by shugo (Shugo Maeda). tr_setup_table_multi() was called twice in String#{strip,strip!}, so I've fixed it: https://github.com/ruby/ruby/pull/15400/commits/c9cb93f201644cd5e2fbbd6e83cf... ### Benchmark https://gist.github.com/shugo/c6367f4139bc2d8df9f9199c49cbbcdf ``` Rehearsal ----------------------------------------------------------------------------- strip() 0.006303 0.001084 0.007387 ( 0.007409) lstrip("\0 \t-\r") 0.003104 0.000000 0.003104 ( 0.003106) sub(/\A[\0\s]+/, "") 0.004521 0.000000 0.004521 ( 0.004522) rstrip("\0 \t-\r") 0.003187 0.000000 0.003187 ( 0.003188) sub(/[\0\s]+\z/, "") 0.016442 0.000000 0.016442 ( 0.016448) strip("\0 \t-\r") 0.003774 0.000000 0.003774 ( 0.003781) gsub(/\A[\0\s]+|[\0\s]+\z/, "") 0.022400 0.000000 0.022400 ( 0.022404) sub(/\A[\0\s]+/, "").sub(/[\0\s]+\z/, "") 0.016304 0.000000 0.016304 ( 0.016320) -------------------------------------------------------------------- total: 0.077119sec user system total real strip() 0.001528 0.000000 0.001528 ( 0.001527) lstrip("\0 \t-\r") 0.002598 0.000000 0.002598 ( 0.002599) sub(/\A[\0\s]+/, "") 0.004651 0.000000 0.004651 ( 0.004657) rstrip("\0 \t-\r") 0.003305 0.000000 0.003305 ( 0.003306) sub(/[\0\s]+\z/, "") 0.014502 0.000000 0.014502 ( 0.014502) strip("\0 \t-\r") 0.003664 0.000000 0.003664 ( 0.003664) gsub(/\A[\0\s]+|[\0\s]+\z/, "") 0.022062 0.000000 0.022062 ( 0.022077) sub(/\A[\0\s]+/, "").sub(/[\0\s]+\z/, "") 0.017203 0.000000 0.017203 ( 0.017207) ``` ---------------------------------------- Feature #21552: allow String.strip and similar to take a parameter similar to String.delete https://bugs.ruby-lang.org/issues/21552#change-115565 * Author: MSP-Greg (Greg L) * Status: Open ---------------------------------------- Regrading `String.strip` (and `lstrip`, `rstrip`, and `!` versions) Some text data representations differentiate between what one might call vertical and horizontal white space, and the 'strip' methods currently strip both. It would be helpful if they had an optional parameter similar to `String.delete` with a one multi-character selector, so one could do: ```ruby t = str.strip " \t" ``` One can use a regex for this, but this much simpler. -- https://bugs.ruby-lang.org/