# Chop and chop!

**URL:** <https://www.ruby-forum.com/t/chop-and-chop/125372>\
**Category:** Ruby\
**Created:** [January 8, 2008, 5:43pm UTC](https://www.ruby-forum.com/t/chop-and-chop/125372 "2008-01-08T17:43:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d9b06d/32.png) [@johnsmith](https://www.ruby-forum.com/u/johnsmith)\
**Post date:** [January 8, 2008, 5:43pm UTC](https://www.ruby-forum.com/t/chop-and-chop/125372/1 "2008-01-08T17:43:36Z")

</div>

hi,

i know for 99% of you this is a very basic question but i was wondering  
what the difference between chop and chop! commands are.

thanks

---

<div class="post-metadata">

**Author:** ![johnsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d9b06d/32.png) [@johnsmith](https://www.ruby-forum.com/u/johnsmith)\
**Post date:** [January 8, 2008, 5:53pm UTC](https://www.ruby-forum.com/t/chop-and-chop/125372/2 "2008-01-08T17:53:53Z")

</div>

Johnathan S. wrote:

> what the difference between chop and chop! commands are.

sorry i meant chomp and chomp!

thanks

---

<div class="post-metadata">

**Author:** ![johnsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d9b06d/32.png) [@johnsmith](https://www.ruby-forum.com/u/johnsmith)\
**Post date:** [January 8, 2008, 5:56pm UTC](https://www.ruby-forum.com/t/chop-and-chop/125372/3 "2008-01-08T17:56:06Z")

</div>

quoth the Johnathan S.:

> hi,
> 
> i know for 99% of you this is a very basic question but i was wondering  
> what the difference between chop and chop! commands are.
> 
> thanks

Generally with Ruby, methods with the ‘!’ are destructive, and modify  
the  
receiver in place:

> s = “foobar\n”  
> =\> “foobar\n”  
> s.chop  
> =\> “foobar”  
> s  
> =\> “foobar\n”  
> s.chop!  
> =\> “foobar”  
> s  
> =\> “foobar”

…here you can see ‘chop’ returns a modified copy, leaving ‘s’ intact,  
whilst ‘chop!’ modifies ‘s’ directly.

HTH,  
-d
