liveBook · Manning

Chop

As explained in The Well-Grounded Rubyist, Fourth Edition

chop is a Ruby String method that returns a string with one character removed from its end.

Ruby’s String#chop removes one character unconditionally from the end of a string. It differs from chomp, which removes a matching ending only when its target is present. section 8.1.5

Remove the final character

"David A. Black".chop returns "David A. Blac". The final character is removed even though it is not a newline or other specified substring. section 8.1.5

How The Well-Grounded Rubyist, Fourth Edition covers it

How deep it goes
Defines unconditional removal and contrasts it with chomp, without detailing implementation internals or broader edge cases.
Examples
Uses "David A. Black".chop to remove the final k and contrasts it with newline and substring removal through chomp.
What you can do after
Apply String#chop to remove exactly one character from a string’s end.
How it connects
Contrasts chop with chomp and relates both to removing characters from string ends.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Rubyist, Fourth Edition. The section links point to the parts of the book it draws on.